Skip to content

Instantly share code, notes, and snippets.

@christianhanvey
Created April 16, 2014 06:58
Show Gist options
  • Save christianhanvey/10820339 to your computer and use it in GitHub Desktop.
Save christianhanvey/10820339 to your computer and use it in GitHub Desktop.
angular safeApply
angular.module('ng').run(['$rootScope', function($rootScope) {
$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