Created
August 18, 2016 18:53
-
-
Save dreamerkumar/5098ce40736c46ae6e7de97bd8883f98 to your computer and use it in GitHub Desktop.
Angular $http interceptor to intercept responses (ref: http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/)
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
'use strict'; | |
(function() { | |
angular.module('mymodule', [ | |
..... | |
]) | |
.config([ | |
'$httpProvider', | |
function ($httpProvider) { | |
$httpProvider.interceptors.push('myInterceptor'); | |
} | |
]) | |
.run([ | |
... | |
]) | |
.factory('myInterceptor', ['$q', function($q) { | |
var myInterceptor = { | |
response: function(response) { | |
var deferred = $q.defer(); | |
window.setTimeout(function() { | |
//intentionally delay for 2 seconds before returning | |
deferred.resolve(response); | |
}, 2000); | |
return deferred.promise; | |
} | |
}; | |
return myInterceptor; | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment