Different use cases, I have actually seen, and also where someone was trying to force a digest or an apply…
1. A finish use case
An use situation to know where is executed once in a cycle
ng-click code begin a new cycle, bike 1We are currently in one $apply phase, for this reason if you speak to $apply() you will acquire an error and calling $digest() is useless because it’s the following phase (and you acquire the exact same error)$evalAsync is useless$timeout password will pressure Angular to develop a brand-new cycle, bike 2 (performance impact)
2. Third-party/DOM occasions use caseThis one is THE most IMPORTANT one, all difficulties come native the lack of $apply contact when you room in the call back of a thirdparty or in the callback of a jquery/DOM event. An extremely often forgot, this is the main cause of a dramatic “… currently in progress” cascade
The good version
DOM event click phone call our code (it might be any type of other DOM occasions or a thirdparty event/callback)As you deserve to see $scope.$apply execute a brand-new cycle v our password inside, it’s perfect, our code is correctly insecuted in Angular contextWe have both phase: $apply & $digestThings acquire worse…
So here, is an instance of something you should never do, utilizing $digest() rather of $apply()
The $apply() step is not executed! the why Angular strongly recommand to never ever use $digest().
You are watching: Apply already in progress
3. In a promise
Using $q, the Angular’s promise library, you are sure to be in the Angular context, so no need to $apply or $digest
Angular develop a brand-new $digest just cycle, once the promise is resolved, so if you speak to $scope.$digest() or $apply() inside the promise deal with callback, you will acquire “$digest currently in progress”
3. In a watcher
Watchers are already in the Angular context, so…
Third party example
An example if you room in a thirdparty, or a DOM event.
You call $apply in the onclick duty because you are out that the Angular context.In the watcher, never contact $apply() or $digest() since you space 100% of the moment in a cycleIn one angular context
I change the use case over with an ng-click, for this reason I’m currently in the Angular context give thanks to to ngClick directive.
See more: How To Plane Wood Without A Planer (Easy Tips And Tricks), Can You Plane Wood Without A Planer
ConclusionI hope this guide will help you to understand how you can totally avoid any type of “$digest/$apply currently in progress”.