Angular update list $rootScope:infdig

131 Views Asked by At

i'm trying to update a scope list inside a callback function. This apparently works fine, but, after some seconds, console gets error: [$rootScope:infdig]. I tried to disable two-way databinding, but, the error continues.

Controller:

app.controller('ChapterCtrl', function ($rootScope, $scope, Services, chapter) {
  $rootScope.headerTitle = chapter.name;
  $scope.terms = [];

  cctdbterms.webdb.getTermsByChapter(chapter.id, function(tx, results) {
      $scope.terms = results.rows;
      $scope.$apply();
  });
});

View:

<div class="view" ng-repeat="term in terms">
    <div ng-bind-html="term.description"></div>
</div>
1

There are 1 best solutions below

0
On

The answer that a find is seraching is: "Problem was that the filter was providing a different array each time hence causing a loop" from Why do I get an infdig error?

Thinking about it, I solved in a simple way, interating my returning list:

app.controller('ChapterCtrl', function ($rootScope, $scope, Services, chapter) {
  $rootScope.headerTitle = chapter.name;
  $scope.terms = [];

  cctdbterms.webdb.getTermsByChapter(chapter.id, function(tx, results) {
      for (var i = 0; i < results.rows.length; i++) {
          var term = results.rows[i];
          $scope.terms.push(term);
      }
      $scope.$apply();
  });
});