简体   繁体   中英

AngularJS - How to pass additional params in $http response

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

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);
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM