Last active
November 23, 2017 12:50
-
-
Save antonydenyer/bac3b5245713d670d6e9 to your computer and use it in GitHub Desktop.
fix IE8 support for catch and finally in angularjs $q service (http://www.antonydenyer.co.uk/blog/2014/08/22/angularjs-decorator-to-support-ie8-catch/)
This file contains hidden or 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
| (function () { | |
| "use strict"; | |
| app.config(function ($provide) { | |
| $provide.decorator('$q', function ($delegate) { | |
| // http://dorp.io/blog/extending-q-promises.html | |
| function decoratePromise(promise) { | |
| promise._then = promise.then; | |
| promise.then = function (thenFn, errFn, notifyFn) { | |
| var p = promise._then(thenFn, errFn, notifyFn); | |
| return decoratePromise(p); | |
| }; | |
| promise.error = promise["catch"]; | |
| promise["catch"] = function () { | |
| throw "Do not use catch as it's not supported by IE8, use error instead"; | |
| }; | |
| promise.always = promise["finally"]; | |
| promise["finally"] = function () { | |
| throw "Do not use finally as it's not supported by IE8, use always instead"; | |
| }; | |
| return promise; | |
| } | |
| var defer = $delegate.defer, | |
| when = $delegate.when, | |
| reject = $delegate.reject, | |
| all = $delegate.all; | |
| $delegate.defer = function () { | |
| var deferred = defer(); | |
| decoratePromise(deferred.promise); | |
| return deferred; | |
| }; | |
| $delegate.when = function () { | |
| var p = when.apply(this, arguments); | |
| return decoratePromise(p); | |
| }; | |
| $delegate.reject = function () { | |
| var p = reject.apply(this, arguments); | |
| return decoratePromise(p); | |
| }; | |
| $delegate.all = function () { | |
| var p = all.apply(this, arguments); | |
| return decoratePromise(p); | |
| }; | |
| return $delegate; | |
| }); | |
| }); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thnx!