2016-09-02 14 views
0

콜백 함수 내에서 범위 목록을 업데이트하려고합니다. 이것은 분명히 잘 작동하지만 몇 초 후에 콘솔에 오류가 발생합니다 : [$ 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> 
+0

왜 '$ scope.apply()'를 추가해야합니까? 제거하고 결과를 게시하십시오. –

+0

'$ scope.apply()'가 없으면 오류가 계속되고 내보기에서 값을 가져올 수 없습니다. –

답변

0

seraching되는 찾기이라고 대답 :에서 "문제가 필터 루프가 발생 될 때마다, 따라서 다른 배열을 제공 이였다" 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(); 
    }); 
}); 
관련 문제