Last active
August 29, 2015 14:11
-
-
Save awerlang/007e11fd415a95c6bb44 to your computer and use it in GitHub Desktop.
Apply some delay on Http Requests
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
// 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