gpt4 book ai didi

javascript - 除非刷新,否则 Firebase 数据不会加载到列表中(AngularJS、Firebase 和 ionic)

转载 作者:行者123 更新时间:2023-11-27 23:13:27 25 4
gpt4 key购买 nike

我的项目列表未正确加载。我得到一个没有错误的空屏幕,一旦刷新,它们就会全部显示出来。我相信 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com