[英]Implement http interceptor in angular.js
我的项目中有 RestCall 服务。我使用 $http.get 从后端获取数据。 我想显示加载图像,直到我获得数据。如何使用拦截器来做到这一点。
第 1 步:在配置中注入 $httpProvider
.config(function($httpProvider...............
第 2 步:按照示例
.config(function($httpProvider){
$httpProvider.interceptors.push(function($rootScope){
return {
request: function(config){
//Show loading
return config ;
},
requestError: function(response){
//Hide loading
return response;
},
response: function(response){
//Hide loading
return response;
},
responseError: function(response){
//Hide loadig
return response;
}
};
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.