Created
July 20, 2015 23:48
-
-
Save kylebuch8/076ca81676f0a72699cb to your computer and use it in GitHub Desktop.
AngularJS httpInterceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.$inject = ['$provide', '$httpProvider']; | |
function config($provide, $httpProvider) { | |
$provide.factory('httpInterceptor', httpInterceptor); | |
httpInterceptor.$inject = ['$rootScope']; | |
function httpInterceptor($rootScope) { | |
return { | |
'request': request, | |
'response': response, | |
'responseError': responseError | |
}; | |
function request(config) { | |
$rootScope.loading = true; | |
return config; | |
} | |
function response(responseObj) { | |
$rootScope.loading = false; | |
return responseObj; | |
} | |
function responseError(rejection) { | |
$rootScope.loading = false; | |
return rejection; | |
} | |
} | |
$httpProvider.interceptors.push(httpInterceptor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment