【发布时间】:2013-04-22 13:58:18
【问题描述】:
在 angularFire 示例中,它展示了如何从 firebase 获取对象集合。
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = 'https://ex.firebaseio.com/stuff';
$scope.col = angularFireCollection(url);
}
]);
只有一个对象呢?
我尝试过这样的事情:
fb.child('stuff/'+id).on('value', function(snapshot) {
$scope.obj = snapshot.val();
console.log('hey got the value')
console.log(snapshot.val())
});
似乎不起作用。控制台正确输出对象值,但控制器没有更新。
【问题讨论】:
-
至于为什么您的尝试没有成功:在角度函数之外修改 $scope 时(例如在 Firebase 回调中),您需要使用 $scope.$apply( )。这里有一个很好的解释:jimhoskins.com/2012/12/17/angularjs-and-apply.html
标签: javascript angularjs firebase angularfire