2
我正在按照http://www.ictit.com/en/blog/post/30/show-loading-screen-globally-and-centralize-in-ionic-angularjs/的确切指南拦截http请求,我想知道是否有可能通过在创建$ http请求时添加某种选项变量来覆盖它?Angularjs覆盖http全局拦截器
我正在按照http://www.ictit.com/en/blog/post/30/show-loading-screen-globally-and-centralize-in-ionic-angularjs/的确切指南拦截http请求,我想知道是否有可能通过在创建$ http请求时添加某种选项变量来覆盖它?Angularjs覆盖http全局拦截器
$httpProvider.interceptors.push(function($rootScope) {
return {
//http request show loading
request: function(config) {
if (!config.override) {
$rootScope.$broadcast('loading:show')
}
return config
},
//hide loading in case any occurred
requestError: function(response) {
if (!config.override) {
alert("requestError");
$rootScope.$broadcast('loading:hide')
}
return response
},
//Hide loading once got response
response: function(response) {
if (!config.override) {
$rootScope.$broadcast('loading:hide')
}
return response
},
//Hide loading if got any response error
responseError: function(response) {
if (!config.override) {
alert("responseError");
$rootScope.$broadcast('loading:hide')
}
return response
}
}
})
在$ HTTP调用简单地传递$http.get(url, {override: true})
在requestError,响应和responseError,配置是不确定的。但是如果你使用'if(!response.config.override){...}',它会起作用。 – JanP
如果我们有帖子? – walox
@walox'''$ http.post(url,data,{override:true})''' –