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
Post a Comment