Firebase CRUD operations for Object
Create an object binding/ Retrieve
| item: AngularFireObject<any>; // db: AngularFireDatabase this.item = db.object('item'); // or Observable<any> item = db.object('item').valueChanges(); |
Create
| // db: AngularFireDatabase const itemRef = db.object('item'); // set() for destructive updates itemRef.set({ name: 'grokonez'}); |
Update
| // db: AngularFireDatabase const itemRef = db.object('item'); itemRef.update({ url: 'grokonez.com'}); |
Delete
| // db: AngularFireDatabase const itemRef = db.object('item'); itemRef.remove(); |
List of Objects
Create a list binding/ Retrieve
– Returns an Observable
of data as a synchronized array of JSON objects without snapshot metadata. It is simple to render to a view:
| items: Observable<any[]>; // db: AngularFireDatabase this.items = db.list('items').valueChanges(); |
– Returns an Observable
of data as a synchronized array of AngularFireAction
<DatabaseSnapshot
>[] with metadata (the underyling DatabaseReference and snapshot key):
| items: Observable<any[]>; // db: AngularFireDatabase this.items = db.list('items').snapshotChanges(); |
Create
| // db: AngularFireDatabase const itemsRef = db.list('items'); itemsRef.push({ site: 'grokonez.com' }); |
Update
| // set(): destructive update // delete everything currently in place, then save the new value const itemsRef = db.list('items'); // db: AngularFireDatabase itemsRef.set('key', { url: 'jsa.com' }); // update(): non-destructive update // only updates the values specified const itemsRef = db.list('items'); // db: AngularFireDatabase itemsRef.update('key', { url: 'javasampleapp.com' }); |
Delete
| // db: AngularFireDatabase const itemsRef = db.list('items'); itemsRef.remove('key'); // delete entire list itemsRef.remove(); |
Comments
Post a Comment