Given this IDs array:
var array = [1,2,3,4,5];
How can I return a promise AFTER all the other calls made within the loop are finished?
var deferred = $q.defer(),
result = [];
for (var i = 0; i < array.length; i++) {
var id = array[i];
Tools.remove(campaignID).then(function(result) {
result.push(result.id);
}).catch(function (response) {
result.push(response)
});
}
deferred.resolve(result);
return deferred.promise;