Last active
August 29, 2015 14:10
-
-
Save lukebussey/0cc38376e020caae4742 to your computer and use it in GitHub Desktop.
Angular $http delay/latency
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
/** | |
* 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