Created
February 8, 2017 09:12
-
-
Save savokiss/e9044dfb54ec95eaaf609f6a70ebc92e to your computer and use it in GitHub Desktop.
AngularJS manual $apply
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
/* | |
* safeApply | |
*/ | |
commonModule.factory('SafeApply', function ($rootScope) { | |
return function (scope, fn) { | |
var phase = scope.$root.$$phase; | |
if (phase == '$apply' || phase == '$digest') { | |
if (fn && (typeof(fn) === 'function')) { | |
fn(); | |
} | |
} else { | |
scope.$apply(fn); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment