Skip to content

Instantly share code, notes, and snippets.

@KazuyaHayashi
Forked from siongui/gist:4969449
Last active August 29, 2015 14:17
Show Gist options
  • Save KazuyaHayashi/da4c745cbd774c08d6b7 to your computer and use it in GitHub Desktop.
Save KazuyaHayashi/da4c745cbd774c08d6b7 to your computer and use it in GitHub Desktop.
$scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest')
this.$eval(fn);
else
this.$apply(fn);
};
// OR
function safeApply(scope, fn) {
var phase = scope.$root.$$phase;
if(phase == '$apply' || phase == '$digest')
scope.$eval(fn);
else
scope.$apply(fn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment