Last active
August 29, 2015 14:06
-
-
Save toboqus/69b2dddd9d3b07c3cf66 to your computer and use it in GitHub Desktop.
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
angular.module('Scope.safeApply', []) | |
.run(['$rootScope', function ($rootScope) { | |
$rootScope.$safeApply = function () { | |
var fn, phase = this.$root.$$phase; | |
if (arguments.length == 1) { | |
fn = arguments[0]; | |
} else { | |
fn = arguments[1]; | |
} | |
if (phase == '$apply' || phase == '$digest') { | |
if (fn && (typeof(fn) === 'function')) { | |
fn(); | |
} | |
} else { | |
this.$apply(fn); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment