I am trying to make few ajax call inside a loop. I want to print a message only when my last ajax is successful. Any suggestions what I am doing wrong here.
$scope.defer = $q.defer();
$scope.promises = [];
$scope.array = [1,2,3,4,5,6,7,8,9,10];
$scope.makecall = function(){
angular.forEach($scope.array, function(index){
$timeout(function() {
var promise = $http({
url : 'https://jsonplaceholder.typicode.com',
method: 'GET',
}).
success(function(data){
});
$scope.promises.push(promise);
}, index * 2000);
});
return $scope.defer.promise;
}
$scope.makecall();
$q.all($scope.promises).then(function(){
console.log('over!');
});