Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FirebaseService<T>

Defines a service that wraps the Firebase Javascript API in a nice, Observable-enabled manner.

Example:

import {FirebaseService} from 'ng2-firebase/core';

// Tell TypeScript that the Firebase SDK has created a global for us
declare var Firebase;

var firebase = new FirebaseService(
   new Firebase('https://YOUR-FIREBASE-URL.firebaseio-demo.com')
);

// Use Service

Angular 2 Example:

// some.component.ts
import { Component, OnInit, provide } from 'angular2/core';
import { FirebaseService, FirebaseServiceFactory } from 'ng2-firebase/core';
import { Observable } from 'rxjs/Rx';

@@Component({
   // FirebaseServiceFactory is not Implemented yet...
   selector: 'some-component',

   // Make sure to include the async pipe so that the most recent value
   // is resolved from the data observable.
   template: 'My Data: {{data | async}}',

   // Declare the providers that should be used for the service.
   providers: [
     provide(FirebaseService, { useFactory: FirebaseServiceFactory })
   ]
})
export class SomeComponent implements OnInit {
  private firebase: FirebaseService;
  data: Observable<any>;

  constructor(firebase: FirebaseService) {
     this.firebase = firebase;
  }

  observeData() {
     this.data = this.firebase.data;
  }

  ngOnInit() {
     this.observeData();
  }
}

Type parameters

  • T

Hierarchy

  • FirebaseService

Index

Constructors

constructor

  • Creates a new FirebaseService using the given Firebase JavaScript API Object.

    Parameters

    • config: any

      Either the FirebaseConfig or Firebase instance that the service should use.

    Returns FirebaseService

Properties

Private _firebase

_firebase: Firebase

Accessors

childAdded

  • get childAdded(): Observable<any>
  • Gets an observable that resolves whenever a child is added to this Firebase location. Internally, this maps to the 'child_added' event emitted by Firebase.

    Returns Observable<any>

childAddedRaw

  • get childAddedRaw(): Observable<any[]>
  • Gets the raw event stream for the 'child_added' event from the underlying Firebase Object.

    Returns Observable<any[]>

childChanged

  • get childChanged(): Observable<any>
  • Gets an observable that resolves whenever the data of a child in this Firebase location is modified. Internally, this maps to the 'child_changed' event emitted by Firebase.

    Returns Observable<any>

childChangedRaw

  • get childChangedRaw(): Observable<any[]>
  • Gets the raw event stream for the 'child_changed' event from the underlying Firebase Object.

    Returns Observable<any[]>

childMoved

  • get childMoved(): Observable<any>
  • Gets an observable that resolves whenever a child is moved in this Firebase location. Internally, this maps to the 'child_moved' event emitted by Firebase.

    Returns Observable<any>

childMovedRaw

  • get childMovedRaw(): Observable<any[]>
  • Gets the raw event stream for the 'child_moved' event from the underlying Firebase Object.

    Returns Observable<any[]>

childRemoved

  • get childRemoved(): Observable<any>
  • Gets an observable that resolves whenever a child is removed from this Firebase location. Internally, this maps to the 'child_removed' event emitted by Firebase.

    Returns Observable<any>

childRemovedRaw

  • get childRemovedRaw(): Observable<any[]>
  • Gets the raw event stream for the 'child_removed' event from the underlying Firebase Object.

    Returns Observable<any[]>

data

  • get data(): Observable<T>
  • Gets an observable that resolves with the data in this Firebase location and whenever the data is updated. Semantically the same as calling .value. Internally, this maps to the 'value' event emitted by Firebase.

    Returns Observable<T>

dataRaw

  • get dataRaw(): Observable<any[]>

firebase

  • get firebase(): Firebase

value

  • get value(): Observable<T>
  • Gets an observable that resolves with the value in this Firebase location and whenever the data is updated. Internally, this maps to the 'value' event emitted by Firebase.

    Returns Observable<T>

valueRaw

  • get valueRaw(): Observable<any[]>
  • Gets the raw event stream for the 'value' event from the underlying Firebase Object.

    Returns Observable<any[]>

Methods

asArray

  • Wraps this FirebaseService in a new FirebaseArray object. The FirebaseArray service provides functionality for dealing with synchronized order lists of objects.

    Returns FirebaseArray<T>

child

  • Gets a child Firebase service that represents the data at the given path.

    Type parameters

    • TChild

    Parameters

    • path: string

      The relative path from this Firebase location to the requested location.

    Returns FirebaseService<TChild>

on

  • on(eventType: string): Observable<any[]>
  • Retrieves an observable that wraps the given event from the Firebase API.

    Parameters

    • eventType: string

      One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved."

    Returns Observable<any[]>

    An object that represents the asynchronous stream of events.

push

  • push(data: any): Promise<boolean>
  • Adds the given data to this Firebase location.

    Parameters

    • data: any

      The data that should be added.

    Returns Promise<boolean>

remove

  • remove(key?: string): Promise<boolean>
  • Removes the child with the given key from this location. If a key is not provided, then this location will be removed from it's parent location.

    Parameters

    • Optional key: string

      The key of the child that should be removed from this location.

    Returns Promise<boolean>

set

  • set(data: T): Promise<boolean>

setData

  • setData(data: T): Promise<boolean>
  • Sets the data exact data that this Firebase location should contain and returns an observable that represents the operation.

    Parameters

    • data: T

      The data that should be set to this location.

    Returns Promise<boolean>

    Returns a promise that resolves true if the data was set. Otherwise the promise rejects if there was an error.

update

  • update(data: T): Promise<boolean>

updateData

  • updateData(data: T): Promise<boolean>
  • Update the objects children in this Firebase location. Passing null to updateData() will remove the value at the specified location. returns an promise that resolves when the operation is succesfull.

    Parameters

    • data: T

      The object containing only the keys that should be updated in this location.

    Returns Promise<boolean>

    Returns a promise that resolves true if the data was succesfully updated. Otherwise the promise rejects if there was an error.

Private wrapFirebaseEvent

  • wrapFirebaseEvent(eventType: string): Observable<any[]>
  • Wraps the given Firebase event type as an observable.

    Parameters

    • eventType: string

      One of the following strings: "value", "child_added", "child_changed", "child_removed", or "child_moved."

    Returns Observable<any[]>

Generated using TypeDoc