Created
December 11, 2012 14:29
-
-
Save halfbaked/4258946 to your computer and use it in GitHub Desktop.
http loading interceptor with spinner provider injected in AngularJs
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
angular.module('http-loading-interceptor', ['spinner']) | |
.config(['$httpProvider', 'spinnerProvider', ($httpProvider, spinnerProvider) -> | |
interceptor = (data, headersGetter) -> | |
spinnerProvider.startSpinner() | |
data | |
$httpProvider.defaults.transformRequest.push(interceptor) | |
]) | |
.config(['$httpProvider', 'spinnerProvider', ($httpProvider, spinnerProvider) -> | |
interceptor = ['$q', '$window', ($q, $window) -> | |
success = (response) -> | |
spinnerProvider.stopSpinner() | |
response | |
error = (response) -> | |
spinnerProvider.stopSpinner() | |
$q.reject(response) | |
return (promise) -> promise.then(success, error) | |
] | |
$httpProvider.responseInterceptors.push(interceptor) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment