Upgrading to AngularFire 5.0

后端 未结 1 1179
你的背包
你的背包 2021-01-28 04:46

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: F         


        
相关标签:
1条回答
  • 2021-01-28 04:54

    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);
      })
    
    0 讨论(0)
提交回复
热议问题