Skip to content

Instantly share code, notes, and snippets.

@lukebussey
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukebussey/0cc38376e020caae4742 to your computer and use it in GitHub Desktop.
Save lukebussey/0cc38376e020caae4742 to your computer and use it in GitHub Desktop.
Angular $http delay/latency
/**
* Delay all $http calls for JSON objects by 2 seconds
* Used to introduce latency to see how things load.
*/
module.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push([
'$q', '$timeout',
function ($q, $timeout) {
var delay = 2;
return {
'response': function(response) {
var defer = $q.defer();
if (typeof(response.data) !== 'object') {
return response;
}
$timeout(function () {
defer.resolve(response);
}, delay * 1000);
return defer.promise;
}
};
}
]);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment