Created
August 9, 2013 08:03
-
-
Save chrisyip/6191914 to your computer and use it in GitHub Desktop.
AngularJS Snippets
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
# 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