Skip to content

Instantly share code, notes, and snippets.

@savokiss
Created February 8, 2017 09:12
Show Gist options
  • Save savokiss/e9044dfb54ec95eaaf609f6a70ebc92e to your computer and use it in GitHub Desktop.
Save savokiss/e9044dfb54ec95eaaf609f6a70ebc92e to your computer and use it in GitHub Desktop.
AngularJS manual $apply
/*
* 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