2015-03-10 3 views
0

Попытка сделать комментируемой код script.js работы: http://plnkr.co/edit/VQCZtqzshMXJA8YTSxdr?p=previewAngularJS Http Перехватчик не работает

Может кто-нибудь помочь?

myApp.config([ 
'$httpProvider', function ($httpProvider) { 



    $httpProvider.interceptors.push(function() { 
     return { 
      'request': function() { 
       // same as above 
       alert('request'); 
      }, 

      'response': function() { 
       // same as above 
       alert('response'); 
      } 
     }; 
    }); 

} 

]);

ответ

0

Нарисуйте ваше внимание на перехватчиков документации

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

+0

Удивительная работа .. Большое спасибо! – Josh

Смежные вопросы