Jor*_*ola 5 javascript angularjs
我一直在寻找一种管理我在角度应用程序中可以拥有的http错误的方法.我一直在分别捕捉它们,但我想在全球范围内管理它们.我使用$ resource和$ http作为我的http调用.有没有办法在全球范围内管理它们?
尝试$http 拦截器:
引用自文档:
angular.module('app',[]).config(function($httpProvider){
$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
'request': function(config) {
return config;
},
'response': function(response) {
// do something on success
return response || $q.when(response);
},
'responseError': function(rejection) {
// do something on error
return $q.reject(rejection);
}
};
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1806 次 |
| 最近记录: |