Skip to content

Instantly share code, notes, and snippets.

@awerlang
Last active August 29, 2015 14:11
Show Gist options
  • Save awerlang/007e11fd415a95c6bb44 to your computer and use it in GitHub Desktop.
Save awerlang/007e11fd415a95c6bb44 to your computer and use it in GitHub Desktop.
Apply some delay on Http Requests
// enabled when $rootScope.configHttpDelay == true
(function () {
"use strict";
angular.module("app")
.config(function ($provide) {
function decorator($delegate) {
var proxy = function (method, url, data, callback, headers) {
var interceptor = function () {
var _this = this,
_arguments = arguments;
var obj1 = angular.element(document.querySelector('.ng-scope')).data();
var delay = obj1.$scope.$root.configHttpDelay;
if (delay) {
var delayMs = 700;
setTimeout(function () {
callback.apply(_this, _arguments);
}, delayMs);
}
else {
callback.apply(_this, _arguments);
}
};
return $delegate.call(this, method, url, data, interceptor, headers);
};
for (var key in $delegate) {
proxy[key] = $delegate[key];
}
return proxy;
}
$provide.decorator('$httpBackend', decorator);
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment