Skip to content

Instantly share code, notes, and snippets.

@ariesjia
Created October 16, 2013 06:00
Show Gist options
  • Save ariesjia/7003240 to your computer and use it in GitHub Desktop.
Save ariesjia/7003240 to your computer and use it in GitHub Desktop.
angular
// https://coderwall.com/p/ngisma
$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