1

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' ?

Phil
  • 157,677
  • 23
  • 242
  • 245
Oskar Szura
  • 2,469
  • 5
  • 32
  • 42
  • You really need to clarify this question. I can't tell what you're trying to do or what you want to achieve – Phil Oct 02 '14 at 06:08
  • within the $q.all.then handler I want to be able not only to access the data from ajax response but also to access data from variable additionalConfig - so the question is how can I pass this object with $http service to be able to access it with AJAX response - it is clear enough now? – Oskar Szura Oct 02 '14 at 06:10
  • I guess this is similar isse -http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback - but I want to solve it with angularJS $q service. – Oskar Szura Oct 02 '14 at 06:13

1 Answers1

2

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);
    });
});
Phil
  • 157,677
  • 23
  • 242
  • 245