如何遍历 $firebaseArray [英] How to loop through $firebaseArray
本文介绍了如何遍历 $firebaseArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我像这样创建了一组用户 -
I created an array of users like so -
var ref = new Firebase(FIREBASE_URL + '/users');
var users = $firebaseArray(ref);
我已经添加了对象,我想遍历这个数组中的每个用户.我知道这在使用 ng-repeat 的视图中是可能的,但我需要在控制器中进行.我试过了 -
I have added objects to this and I want to loop through each of the users in this array. I know this is possible in the view using ng-repeat, but I need to do it in the controller. I have tried -
angular.forEach(users, function(user) {
console.log(user);
})
但我没有得到任何结果.
But I get no result from this.
推荐答案
届时可能尚未加载用户,因此您需要等待:
Users probably isn't loaded by then, so you'll need to wait for it:
var ref = new Firebase(FIREBASE_URL + '/users');
var users = $firebaseArray(ref);
users.$loaded()
.then(function(){
angular.forEach(users, function(user) {
console.log(user);
})
});
这篇关于如何遍历 $firebaseArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文