Reputation: 3608
I'm using ionic 3 with firebase.
Until now I use angularfire 4.0 and the following code gave me an observable for the data from firebase:
obsToData: FirebaseObjectObservable<any>;
constructor(public nav: NavController, public shared: SharedProvider,
public DB: AngularFireDatabase) {
this.obsToData = DB.object('/myData');
}
now, according to this page FirebaseObjectObservable
removed and I need to use AngularFireObject
instead, how can I get the data?
I did the following change:
obsToData: AngularFireObject<any>;
constructor(public nav: NavController, public shared: SharedProvider,
public DB: AngularFireDatabase) {
this.obsToData = DB.object('/myData');
}
but I don't find the way how to get an observable from this new object to my data from firebase.
Does someone succeed to use angularfire 5.0?
Upvotes: 0
Views: 602
Reputation: 29614
you need to use valueChanges()
to get the Observable from the AngularFireDatabase Object reference.
obsRef: AngularFireObject<any>;
obsToData: Observable<any>;
constructor(public nav: NavController, public shared: SharedProvider,
public DB: AngularFireDatabase) {
this.obsRef = DB.object('/myData');//reference
this.obsToData = this.obsRef.valueChanges();//Observable
}
EDIT to get data and save it,subscribe like any observable
this.obsToData.subscribe(data=>{
console.log(data);
},error=>{
console.log(error);
})
Upvotes: 2