I want to ensure that the for loop is successfully executed and then the result is passed to the next function:
FindIdsRequests = function(){
results = $scope.requests
var deferred = $q.defer();
var promise = deferred.promise;
var array = []
for (var i in results) {
promise = promise.then(function(){
array.push(results[i].uid)
})
return promise
}
return promise.then(function(){
return array
})
}
$scope.ConfirmRequests = function(){
//alert('req'+JSON.stringify($scope.requests))
FindIdsRequests().then(function(array){
alert('arr'+JSON.stringify(array))
})
})
It seems that the FindIdsRequests function should be returning the result of the for loop, but it doesn't (the alert message is not displayed, so it seems not to be reaching that point). Any suggestions?