Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save halfbaked/4258946 to your computer and use it in GitHub Desktop.
Save halfbaked/4258946 to your computer and use it in GitHub Desktop.
http loading interceptor with spinner provider injected in AngularJs
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