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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -