简体   繁体   中英

Implement http interceptor in angular.js

I am having RestCall service in my Project.I am using $http.get to fetch data from backend. I want to display loading image until i get data .How to do this by using interceptor.

Step 1: in config inject $httpProvider

.config(function($httpProvider...............

Step 2: follow sample

.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;
            }
        };
    });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM