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})''' –