<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,上面是我正在使用的代码,但这个循环将无限时间,我不明白我做错了什么,有人可以帮助我吗
答案 0 :(得分:0)
您无法在$http
内调用ng-repeat
服务,因为它会导致无限循环。说明:angular Infinite $digest Loop in ng-repeat。希望这会有所帮助。
您可以事先为$scope.getData()
调用id
,将结果存储到数组中,然后在ng-repeat
中调用此数组。