Skip to content

Instantly share code, notes, and snippets.

@imbdb
Created December 8, 2016 06:21
Show Gist options
  • Save imbdb/a6dfcafac22a9a40873786a43401233f to your computer and use it in GitHub Desktop.
Save imbdb/a6dfcafac22a9a40873786a43401233f to your computer and use it in GitHub Desktop.
Angular safeApply
$scope.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