Created
June 23, 2016 08:27
-
-
Save tkssharma/4304d78b0760396cea90532910910e69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$rootScope.$safeApply = function($scope, fn) { | |
fn = fn || function() {}; | |
if($scope.$$phase) { | |
//don't worry, the value gets set and AngularJS picks up on it... | |
fn(); | |
} | |
else { | |
//this will fire to tell angularjs to notice that a change has happened | |
//if it is outside of it's own behaviour... | |
$scope.$apply(fn); | |
} | |
}; | |
//and you can run it like so. | |
$scope.some_value = 'value...'; | |
$scope.$safeApply($scope, function() { | |
//this function is run once the apply process is running or has just finished | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment