Last active
August 29, 2015 14:09
-
-
Save JediMindtrick/f737a1a0e5b0d059deb8 to your computer and use it in GitHub Desktop.
Function for safely applying a AngularJS $scope.$apply regardless of $digest phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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