Created
November 19, 2013 18:10
-
-
Save missinglink/7549737 to your computer and use it in GitHub Desktop.
AngularJS SafeApply. This fixes the annoying angular error: "Error: $digest already in progress"
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
| app.factory( 'SafeApply', function() { | |
| return function($scope, fn) { | |
| var phase = $scope.$root.$$phase; | |
| if(phase == '$apply' || phase == '$digest') { | |
| if(fn && (typeof(fn) === 'function')) { | |
| fn(); | |
| } | |
| } else { | |
| $scope.$apply(fn); | |
| } | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: