Skip to content

Instantly share code, notes, and snippets.

@codfish
Created October 24, 2014 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codfish/17f39d3814bb41dcefe1 to your computer and use it in GitHub Desktop.
Save codfish/17f39d3814bb41dcefe1 to your computer and use it in GitHub Desktop.
Angular safe apply
$rootScope.safeApply = function (fn) {
var phase = this.$root.$$phase;
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