admin管理员组文章数量:1387461
In the angularFire examples it shows how to get a collection of objects from firebase.
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = '';
$scope.col = angularFireCollection(url);
}
]);
What about a single object only?
I tried something like this:
fb.child('stuff/'+id).on('value', function(snapshot) {
$scope.obj = snapshot.val();
console.log('hey got the value')
console.log(snapshot.val())
});
Doesn't seem to work. The console outputs the object value correctly but the controller doesn't update.
In the angularFire examples it shows how to get a collection of objects from firebase.
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = 'https://ex.firebaseio./stuff';
$scope.col = angularFireCollection(url);
}
]);
What about a single object only?
I tried something like this:
fb.child('stuff/'+id).on('value', function(snapshot) {
$scope.obj = snapshot.val();
console.log('hey got the value')
console.log(snapshot.val())
});
Doesn't seem to work. The console outputs the object value correctly but the controller doesn't update.
Share Improve this question edited Apr 29, 2013 at 5:20 Andrew Lee 10.2k3 gold badges48 silver badges40 bronze badges asked Apr 29, 2013 at 0:21 HarryHarry 55.1k76 gold badges187 silver badges270 bronze badges 1- 1 As for why your attempt didn't work: when modifying $scope outside of an angular function (like in that Firebase callback), you need to manually trigger a $digest with $scope.$apply(). There's a pretty good explanation here: jimhoskins./2012/12/17/angularjs-and-apply.html – bennlich Commented Oct 8, 2013 at 18:50
1 Answer
Reset to default 9Try using the regular angularFire service, and specifying the type of your single object:
app.controller('ctrl', ['$scope', '$timeout', 'angularFire',
function($scope, $timeout, angularFire) {
var url = 'https://ex.firebaseio./stuff';
angularFire(url, $scope, "obj", "");
}
]);
Note the 4th argument (" " means string, you can also use booleans, numbers, objects and arrays).
本文标签: javascriptAngularFire single objectStack Overflow
版权声明:本文标题:javascript - AngularFire single object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744543401a2611748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论