我的项目列表未正确加载。我得到一个没有错误的空屏幕,一旦刷新,它们就会全部显示出来。我相信 firebase 数据的检索速度不够快,但我不知道该怎么办。我尝试了很多事情但没有运气。预先感谢您!
app.controller('SpotsCtrl', function($state, $scope, $stateParams) {
var firebaseRef = new Firebase("https://myBrokenApp.firebaseio.com/spots");
firebaseRef.child('0').on('value', function(dataSnapshot){
console.log("hello");
$scope.spots = dataSnapshot.val();
console.log($scope.spots);
})
});
//HTML
<ion-list show-delete="spot.showDelete" show-reorder="spot.showMove">
<ion-item
class="item-avatar-left item-icon-right item-remove-animate"
ng-repeat="spot in spots"
href="#/tab/spots/{{spot.name}}">
<h2>{{ spot.name }}</h2>
<p>{{ spot.title }}</p>
<p>{{ spot.loc }}</p>
<i class="icon ion-ios-clock-outline "></i>
<ion-delete-button ng-click="deleteSpot($index)"
class="ion-minus-circled">
</ion-delete-button>
<ion-reorder-button class="ion-navicon"
on-reorder="moveSpot(spot, $fromIndex, $toIndex)">
</ion-reorder-button>
</ion-item>
</ion-list >
最佳答案
尝试将 firebaseref 绑定(bind)到 $firebaseObject。
app.controller('SpotsCtrl', function($state, $scope, $stateParams, $firebaseObject) {
var firebaseRef = new Firebase("https://myBrokenApp.firebaseio.com/spots");
$scope.spots = {};
var spots = $firebaseObject(firebaseRef.child('0'));
spots.$loaded().then(function() {
$scope.spots = spots;
console.log($scope.spots);
});
});
关于javascript - 除非刷新,否则 Firebase 数据不会加载到列表中(AngularJS、Firebase 和 ionic),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36005730/