Reputation: 85
Im trying to use the $q.defer, $q.all and promises in order to wait for a list of http requests
i uses this code to call the $q.all
$q.all(promises).then(function(data) {
console.log('All promises have resolved', data);
var retVal = Utils.DoStep2();
console.log(retVal);
});
this function is never called altough i checked and the $http.get is called for all of the values.
var deferred = $q.defer();
$http.get(requestUrl).
then(function (data) {
var p = {
data: data,
name: name
};
pData.push(p);
deferred.resolve(p);
return p;
})
.catch(function (status) {
deferred.reject(status);
});
promisesList.push(deferred.promise);
Im printing on DoStep2 the length of pData and also the pData using console.log and what i get is the length of 0 and Looking like 0 objects but when i open it it looks like all of the objects are initalized within the $http.get call for each specific call which made me sure that the $http.get response recieved and it's a valid response.
Also the $all isn't called at all what could be wrong?
Thanks for your assistance
Upvotes: 1
Views: 189
Reputation: 85
OK Managed to fix it up I used service function getService() and this function returned the promise then in each call i added the getService() promise returned to the promisesList this list i waited for using $all and it worked thanks alot for your assistance.
Upvotes: 1