angularjs - Retrieving my data from firebase 3 -
i've been attempting obtain data firebase 3 , wondering if knew of error making.
service:
.service("searchservice", function($firebasearray, fb) { var database = firebase.database(); var bookid = firebase.auth().currentuser; this.getpostedbooks = function() { return database.ref("postedbooks/" + bookid).once("value"); }
controller:
$scope.getpostedbooks = function() { searchservice.getpostedbooks().then(function(response) { $timeout(function() { console.log(response.val()) }, 5000); })
i attempted use timeout see if data coming in late, no matter what, null.
you try $q service
https://docs.angularjs.org/api/ng/service/$q
.service("searchservice", function($firebasearray, $q, fb) { var database = firebase.database(); var bookid = firebase.auth().currentuser; var dfd = $q.defer(); return { getpostedbooks : function() { return database.ref("postedbooks/" + bookid).once("value", function(snapshot) { dfd.resolve(snapshot.val()); }, function (errorobject) { //log error }); return dfd.promise; } } })
Comments
Post a Comment