I am trying to detect if the foreach statement is completed together with the statements inside the foreach. From my research, many are asking to use promises. As I am implemented it, it is not executing the way I was expecting.
var uploadUrl = "/api/upload";
$('#add_product').closeModal();
var promises = angular.forEach(vm.images_selected, function(value , key){
return File_Upload.uploadFileToUrl(value, uploadUrl)
.success(function(result){
vm.images_selected_uploaded.push(result);
console.log('here')
});
})
$q.all(promises).then(function () {
console.log('there')
console.log(vm.images_selected_uploaded)
})
From the code above (let's say the value length is 2, the output will be
there
here
here
What I really wanted was here here there. What am I missing here?
successtothenin$q.all()..forEachshould be.map(assuming angular.forEach/angular.map are similar functionally to array.prototype.forEach/array.prototype.map ... hmmm, no angular.map ...