Skip to content

Instantly share code, notes, and snippets.

@slattery
Forked from siongui/gist:4969449
Created June 4, 2014 20:48
Show Gist options
  • Save slattery/018b44278022ea58138f to your computer and use it in GitHub Desktop.
Save slattery/018b44278022ea58138f 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