2016-07-28 87 views
0
<table> 
    <tr ng-repeat="objective in objectives"> 
     <td> 
      <p> {{objective.name}} </p> 
      <table> 
      <tr ng-repeat="data in getData(objective.id)"> 
       <td> {{data.value}} </td> 
      </tr> 
      </table> 
     </td> 
    </tr> 
</table> 

my controller code is --- 

objectiveService.getObjective().success(function (data) { 
    $scope.objectives = data; 
    $scope.loading = false; 
}) 
.error(function (data) { 
    $scope.error = "An Error has occured while loading posts! " + data.ExceptionMessage; 
    $scope.loading = false; 
}); 


$scope.getData = function (id) { 
    $scope.loading = true; 
    var currentObjective = id; 
    objectiveService.getObjectiveById(currentObjective).success(function (data) { 


     $scope.loading = false; 
     return data; 

    }).error(function (data) { 
     $scope.error = "An Error has occured while Saving Objective! " + data.ExceptionMessage; 
     $scope.loading = false; 

    }); 
}; 

我在AngularJS工作,以上是我的代碼,我使用的,但這個循環是要無限長的時間,我不明白的地方,我沒有錯,任何人都可以請幫我AngularJS NG-REPEAT循環內NG-重複是那張無限

+0

介意分享js代碼? – doge1ord

+0

可以顯示你的控制器? getData是做什麼的? –

+0

我編輯了這個問題,請檢查 –

回答

0

你不能在ng-repeat裏面調用$http服務,因爲它會導致無限循環。說明:angular Infinite $digest Loop in ng-repeat。希望這可以幫助。

事先您可以每id調用$scope.getData(),將結果存儲到數組中,然後在ng-repeat中調用該數組。