Skip to content

Instantly share code, notes, and snippets.

@MehulATL
Created November 6, 2014 23:00
Show Gist options
  • Save MehulATL/1ab776b0dae73925c277 to your computer and use it in GitHub Desktop.
Save MehulATL/1ab776b0dae73925c277 to your computer and use it in GitHub Desktop.
safeApply()
var safeApply = function (fn) {
var phase = $rootScope.$root.$$phase;
if (phase === '$apply' || phase === '$digest') {
if (fn && typeof fn === 'function') {
fn();
}
} else {
$rootScope.$apply(fn);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment