Firebase Flashcards
install angularfire2
npm install angularfire2 firebase –save
adjust environments.ts
add “AngularFireModule.initializeApp(environment.firebase)” to imports
import AngularFireDatabaseModule too
disguise the last characters of your API key by
changing it from WXI to IXW
what to inject from AngularFire2
constructor(db: AngularFireDatabase)
how to bind to a list
items: FirebaseListObservable;
constructor(db: AngularFireDatabase) {
this.items = db.list(‘/items’);
}
how to retrieve an object
db.object(‘/item’)
FirebaseObservable methods
set(value) is a destructive update
update(value) is nondestructive (only updates included values)
remove()
Data retrieved from the object binding contains
special properties retrieved from the unwrapped Firebase DataSnapshot
What is the metafield $key
The key for each record. This is equivalent to each record’s path in our database as it would be returned by ref.key()
What is the metafield $value
If a primitive, the primitive value will be stored under $value and can be changed and saved like any other field
By default, AngularFire2 unwraps the
Firebase DataSnapshot, but you can get the data as the original snapshot by specifying the preserveSnapshot option
How to retrieve a Firebase list by query
db.list(‘/items’, {
query: {
limitToLast: 10,
orderByKey: true
}
})