简体   繁体   中英

Angular debugging using Firebug

I´m making an AngularJS app, which fetches data from the Firebase cloud. The data is shown on page but when I debug my controller, it shows an empty list of articles. Why is my variable shown as empty during debugging?

Here is the code of my controller:

appMainModule.controller('GetCtrl', ['$scope', '$firebaseArray', function ($scope, $firebaseArray) {
  var firebaseObj = new Firebase("URL")
  debugger;
  //var sync = $firebaseArray(firebaseObj);
  //$scope.articles = sync.$asArray();
  $scope.articles = $firebaseArray(firebaseObj);

  var firebaseObj1 = new Firebase("URL");

  $scope.articles1 = $firebaseArray(firebaseObj1.orderByChild("Month").equalTo("Apr-2016"));
  var query=$scope.articles1
  var num = query.length;
}]);

And here is my HTML code:

<div class="content" style="height: 380px; overflow: auto;">
  <table class="table">
    <thead>
      <tr>
        <th>Incident Name</th>
        <th>Category</th>
        <th>Month</th>
        <th>Total</th>
      </tr>
    </thead>
    <tbody ng-repeat="article in articles1 ">
      <tr>
        <td><p>{{article.IncidentName}}</p></td>
        <td><p>{{article.CategoryParent}}</p></td>
        <td><p>{{article.Month}}</p></td>
        <td><p>{{article.Total}}</p></td>
      </tr>
    </tbody>
</div>      

Within the HTML page articles1 is providing the data, but within the controller it is shown as empty after fetching the data.

I solved my problem, I was expecting my data so early as it was asyncrounous call to firebase. so here is the method when firebase returns a promise for data

$scope.articles1.$loaded(function(data){
// do here with data,what you want
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM