angularjs - DataSnapshot.val() doesn't return processed value immediately -


this method within factory:

kbuser.getcurrentuserdetails = function(){     return $rootscope.ref.child("user/" + firebase.auth().currentuser.uid).once('value', function(snap){         return snap.val();     }); } 

i call method in controller this:

return kbuser.getcurrentuserdetails().then(function(details){      // here need .val() once again     (var attrname in details.val()) { kbuser.userobject.details[attrname] = details.val()[attrname]; }     kbuser.copyfirebasedatatouser(firebaseuser).then(function(){         return true;     }); }); 

this returned: details = w {a: p, w: u, g: ve}, doesn't correspond database.

when read details variable here, have details.val() again expected json object database. don't why result of snap.val() isn't returned in method, 'raw' firebase datasnapshot snap. know why occurs?

assume factory setup correctly.

basically need use chain promise when snap.val() gets return can data in it.

kbuser.getcurrentuserdetails().then(function(data){   var user = data; });  

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -