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;

    });
};

i am working on AngularJS, above is my code which i am using, but this loop is going to infinite time and i don't understand where i did wrong, can anyone please help me

1 Answers1

0

You cannot call an $http service inside ng-repeat, because it results in infinite loops. Explanation: angular Infinite $digest Loop in ng-repeat. Hope this helps.

You can call $scope.getData() for every id beforehand, store the results into an array, and then call this array in ng-repeat.

Community
  • 1
  • 1
6324
  • 4,678
  • 8
  • 34
  • 63