在angular.js中实现http拦截器

时间:2016-05-28 07:37:47

标签: javascript angularjs

我在我的Project中使用RestCall服务。我使用$ http.get从后端获取数据。我想显示加载图像,直到我得到数据。如何通过使用拦截器来做到这一点。

1 个答案:

答案 0 :(得分:0)

步骤1:在config中注入$ 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;
            }
        };
    });
})
相关问题