angular - Firebase 3 - Ionic 2 - .on('value' , snapshot => { this...} this is null -
when try retrieve data using firebase 3 sdk web, "this" showing null. idea why might occur ?
this.mainapp = firebase.initializeapp(config); fbget(path){ return this.mainapp.database().ref(path); } ... getuser(){ this.appdata.fbget('users/'+user.uid).on('value', function(snapshot) { var objuser = snapshot.val(); //the following statement throwing exception cause 'this' null this.events.publish('user:update', objuser); }); }
thank you
you're not using arrow function fbget
, this
not bound component/provider.
getuser(){ this.appdata.fbget('users/'+user.uid).on('value', (snapshot) => { const objuser = snapshot.val(); // bound component using fat arrow => this.events.publish('user:update', objuser); }); }
the above solution work if this.events
property on same component/provider.
Comments
Post a Comment