Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AngularJS Snippets
# http://docs.angularjs.org/api/ng.$http
#
# - display loading effect
# - do other jobs before request start
# - ...
angular
.module('httpRequestServices', [])
.config(['$httpProvider', ($httpProvider) ->
# fired before each $http request
# can add multiple interceptor
$httpProvider.responseInterceptors.push 'requestStartInterceptor'
])
.factory('requestStartInterceptor', () ->
(promise) ->
console.log 'request started', arguments
# MUST return the promise object or value, otherwise $http request should not start
promise
)
# inject into root app module
angular
.module('myApp', ['httpRequestServices'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment