Reputation: 2569
How to pass additional config to $http service response? Code as below:
var promises = [];
angular.forEach(rows, function(rowIterator) {
var additionalConfig = {
config1: rowIterator.config1,
config2: rowIterator.config2
}
promise = $http({
method: "get",
url: "http://domain.com/" + rowIterator.videoId + '?appName=playlist',
params: {}
});
promises.push(promise);
});
return $q.all(promises).then(function(data) {
// handle data from all promises WITH passed custom configs
});
so how can I read within $q.all fetched data WITH passed configs from 'additionalConfig' ?
Upvotes: 1
Views: 188
Reputation: 164969
This is a wild stab in the dark but how about chaining the response promises like this...
promises.push(promise.then(function(response) {
return {
response: response,
additionalConfig: additionalConfig;
};
}));
Then...
return $q.all(promises).then(function(data) {
angular.forEach(data, function(obj) {
console.log('Response', obj.response);
console.log('Additional config', obj.additionalConfig);
});
});
Upvotes: 2