Skip to content

Instantly share code, notes, and snippets.

@chrisyip
Created August 9, 2013 08:03
Show Gist options
  • Save chrisyip/6191914 to your computer and use it in GitHub Desktop.
Save chrisyip/6191914 to your computer and use it in GitHub Desktop.
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