2016-03-15 42 views
1

我的項目列表未正確加載。我得到一個沒有錯誤的空白屏幕,一旦我刷新,它們都顯示出來。我相信firebase數據並沒有被快速找回,但我不知道該怎麼做。我嘗試了許多事情,但沒有運氣。先謝謝你!Firebase數據不會在列表中加載,除非刷新(angularJS,firebase&ionic)

app.controller( 'SpotsCtrl',函數($狀態,$範圍,$ 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 > 

回答

1

嘗試firebaseref結合你到$ 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); 
    }); 
}); 
+0

感謝您的答覆,與沒有運氣:(任何其他的想法? –

+0

嗯,好吧..嘗試包裝'firebaseRef.child( '0')。在( '值',函數(dataSnapshot) {...'在'$ timeout(function(){firebaseRef.child ...});' – aup

+0

nope:/一旦屏幕加載,如果數據沒有準備好,它只是保持空白,直到我刷新 –