Нарисуйте ваше внимание на перехватчиков документации
Interceptors
request: interceptors get called with a http config object. The function is free to modify the config object or create a new one. The function needs to return the config object directly, or a promise containing the config or a new config object.
requestError: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.
response: interceptors get called with http response object. The function is free to modify the response object or create a new one. The function needs to return the response object directly, or as a promise containing the response or a new response object.
responseError: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.
myApp.config([
'$httpProvider',
function($httpProvider) {
$httpProvider.interceptors.push(function() {
return {
'request': function(config) {
// same as above
alert('request');
return config;
},
'response': function(data) {
// same as above
alert('response');
return data;
}
};
});
}
]);
Plunker
Удивительная работа .. Большое спасибо! – Josh