Har*_*rry 9 javascript angularjs firebase angularfire
在angularFire示例中,它显示了如何从firebase获取对象集合.
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = 'https://ex.firebaseio.com/stuff';
$scope.col = angularFireCollection(url);
}
]);
Run Code Online (Sandbox Code Playgroud)
那只是一个对象呢?
我试过这样的事情:
fb.child('stuff/'+id).on('value', function(snapshot) {
$scope.obj = snapshot.val();
console.log('hey got the value')
console.log(snapshot.val())
});
Run Code Online (Sandbox Code Playgroud)
似乎没有用.控制台正确输出对象值,但控制器不更新.
尝试使用常规的angularFire服务,并指定单个对象的类型:
app.controller('ctrl', ['$scope', '$timeout', 'angularFire',
function($scope, $timeout, angularFire) {
var url = 'https://ex.firebaseio.com/stuff';
angularFire(url, $scope, "obj", "");
}
]);
Run Code Online (Sandbox Code Playgroud)
注意第四个参数(""表示字符串,您也可以使用布尔值,数字,对象和数组).
| 归档时间: |
|
| 查看次数: |
2276 次 |
| 最近记录: |