I want to iterate over a loop and call a service (which is asynchronus) for each item -
for(var i=0;i<$scope.objs.length;i++) {
var obj= $scope.objs[i];
api.invoke({
//parameters
}).then(function (members) {
$scope.setInfo(obj.name,members);
}, function (fail) {
console.log("failed");
});
}
But, as it is asynchronus , obj value is getting ovrewritten before I can send it to the method - setInfo(). How can I avoid it?