Skip to content

Instantly share code, notes, and snippets.

@JediMindtrick
Last active August 29, 2015 14:09
Show Gist options
  • Save JediMindtrick/f737a1a0e5b0d059deb8 to your computer and use it in GitHub Desktop.
Save JediMindtrick/f737a1a0e5b0d059deb8 to your computer and use it in GitHub Desktop.
Function for safely applying a AngularJS $scope.$apply regardless of $digest phase
function runScope(angularScope,callback){
var result = void 0;
var phase = angularScope.$root.$$phase;
if(phase == '$apply' || phase == '$digest'){
result = callback === undefined ? void 0 : callback(angularScope);
}else{
angularScope.$apply(function(){
result = callback === undefined ? void 0 : callback(angularScope);
});
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment