角度更新列表$ rootScope:infdig

时间:2016-09-02 12:54:03

标签: angularjs angularjs-rootscope angularjs-infdig

我试图更新回调函数中的范围列表。这显然工作正常,但是,几秒钟后,控制台出错: [$ rootScope:infdig] 。我试图禁用双向数据绑定,但是,错误仍在继续。

控制器:

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

查看:

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

1 个答案:

答案 0 :(得分:0)

查找搜索的答案是:&#34;问题是过滤器每次都提供不同的数组,因此导致循环&#34;来自Why do I get an infdig error?

考虑到这一点,我以一种简单的方式解决了我的回归清单:

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