I'm currently working on a piece of code that iterates through an array containing 10 items. For each item, a request is made and the returned data is stored in another array. The entire process goes smoothly until reaching the line that contains $q.all
.
details.fetchDetails = function(ids, pageNumber) {
var page = ids[pageNumber],
mainDeferred = $q.defer(),
promises = [],
combinedData = [];
for(var i=0; i<page.length; i++){
var deferred = $q.defer();
ngGPlacesAPI.placeDetails({placeId: page[i][i]})
.then(function(data){
combinedData.push(data);
console.log(combinedData); /// Outputting the objects being added to the array
deferred.resolve();
});
promises.push(deferred.promise);
}
console.log(promises); /// Showing the 10 promises
$q.all(promises).then(function() { /// Nothing executes after this point
console.log('test', mainDeferred.promise); /// No log output here
mainDeferred.resolve(combinedData);
});
return mainDeferred.promise;
};