I have some code in angularJS like this:
$scope.myArray= [{name:"thomas", parentId: 1}, {name:"john", parentId: 2}]
for(var i = 0; i< $scope.myArray.length, i++){
// I wish this code run as blocking code
$http.get('getParentById'+$scope.myArray[i].parentId).then(function(result){
if(result){
$scope.myArray[i].parentName = result.data;
}
});
}
My intention very clearly, assigns parentName for each object get by Http request. But the problem is asynchronous in angularJs. I have tried many ways but it can not be fixed. Does anyone have a solution for this?
EDIT: I got an answer in the comment below. The solution is using angular.foreach()