Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created November 25, 2013 03:14
Show Gist options
  • Select an option

  • Save PatrickJS/7635748 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/7635748 to your computer and use it in GitHub Desktop.
angular.module('YOUR_APP').config([
'$provide', function($provide) {
return $provide.decorator('$rootScope', [
'$delegate', function($delegate) {
$delegate.safeApply = function(fn) {
var phase = $delegate.$$phase;
if (phase === "$apply" || phase === "$digest") {
if (fn && typeof fn === 'function') {
fn();
}
} else {
$delegate.$apply(fn);
}
};
return $delegate;
}
]);
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment