Infinite Loop When Ng-repeat/ng-class Calls A Function Which Calls $http
If you have no idea what this is, please read this :Infinite loop with Angular expression binding In the html file:
Solution 1:
First, your html should not be calling functions pretty much ever (except for on click or something like that.
<uing-repeat="carrierDetail in carrierDetails"><li><ing-class="{'icon-sign-blank':carrierDetail.carrierId==0,'icon-green':carrierDetail.carrierId==1,'icon-orange':carrierDetail.carrierId==2,'icon-red':carrierDetail.carrierId==3}"></i><ulng-repeat="owner in owners"><li>{{owner.ownerName}}</li></ul></li></ui>
The JS, the general idea is:
// assuming controller defined:$scope.carriers = some kind of array;
$scope.getOwners = function(carrierId) {
$http.get($scope.baseurl.smart,carrierId,1).then(function(data) {
return data.data.carrierOwners; // Returns an arary
}, function(data) {
return [];
});
}
$scope.getStatus = function(carrierId) {
$http.get($scope.baseurl.smart,carrierId,1).then(function(data) {
return [1, 2, 3].indexOf(data.data.carrierStatus) != -1 ? data.data.carrierStatus : 0; // Returns an integer
}), function(data) {
return0;
};
}
for( var i in $scope.carriers){
$scope.getOwners( $scope.carriers[ i ].carrierId ).then(function(success){
// add data to array
});
}
Post a Comment for "Infinite Loop When Ng-repeat/ng-class Calls A Function Which Calls $http"