Sometimes I need to use $scope.$apply, for example, when I use jQuery ajax or some non-w500> -js eventlisteners. In such cases, I have an asynchronous callback, and there I use $scope.$applyso that changes in the area are picked up by angular and the clock works. Please correct me if this is a misuse $scope.$apply.
This seems to work and the view is being updated. However, in some fairly rare cases, I get a "digest is already in process" error. I do not see how this is possible, since the callback is not synchronous. So I'm wondering if it is possible that my asynchronous callback with $scope.$applyin it might accidentally run into the current digest? If so, how can I prevent this?
change
One way to check the digest is to check $$ phase:, if (!$scope.$$phase) $scope.$apply()but this is an anti-pattern, as the wiki says: https://github.com/angular/angular.js/wiki/Anti-Patterns
I want to fully understand why it is possible that I came across a digest in an asynchronous callback. And why is it antipattern?
source
share