Answer the question
In order to leave comments, you need to log in
Angular $digest loop?
For example, we added the expression {{ hello }} and Angular created a function for it that will track changes. Then we added the ng-click directive and hung the handler. It is clear that Angular launches a $digest cycle, in fact, thanks to which the 2-way data binding works. BUT, I'll quote:
Angular is not that easy. AngularJS doesn't call $digest directly, it calls the $scope.$apply() function which calls $rootScope.digest(). And as a result, the digest cycle in $rootScope visits the child $scopes one by one and calls their digest cycles.
Answer the question
In order to leave comments, you need to log in
The maximum depth will be
You never know, you have a service that is used in 10 controllers within the same page in different views. How can they find out about the changes? - $rootScope.$digest() .
When I am sure that I need to run something within one element, and this is VERY performance critical, I will create a custom directive in which instead of $scope.$apply() I will write $scope.$$phase || $scope.$digest() . Only watchers within the same $scope will be checked .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question