Firebase数据未在列表中加载,除非刷新(angularJS,firebase& ionic)

时间:2016-03-15 08:14:56

标签: javascript angularjs angularjs-directive firebase

我的商品列表未正确加载。我得到一个没有错误的空屏幕,一旦我刷新,它们都出现了。我相信firebase数据的检索速度不够快,但我不知道该怎么办。我尝试了多件事而没有运气。提前谢谢!

app.controller('SpotsCtrl',函数($ state,$ scope,$ stateParams){

<div class="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</div>  

});

// HTML

   

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);
})

1 个答案:

答案 0 :(得分: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);
  });
});