Reputation: 3498
I am trying to understand the Angular1 $digest cycle. I've read in multiple articles that the digest cycle is called multiple times on every change.
In this article it says:
So once we traversed all of the $watch functions in the $watch list, are we done with the $digest loop? No, we go through the list ONE more time and verify that nothing has changed. We do this because there could have been a change to one of the values when another $watch item updated it. We continue through this loop until no changes are present in any of the values.
So my question is - in what scenario there could have been a change to one of the values when another $watch item updated it?
Upvotes: 0
Views: 382
Reputation: 640
this may not be the perfect example in real use cases, but things like this could happen.
$scope.$watch('Var_A', function(){
// change Var_B
});
$scope.$watch('Var_B', function(){
// do something
});
Var_A and Var_B are put into the $watch list. Say that there is an angular change that changes Var_A, it triggers the first $digest cycle and Var_B changes. The first $digest cycle is not aware Var_B has changed. It then goes through the list one more time and will find that Var_B changes. After this, it goes through the list again and makes sure nothing in the $watch list got changed.
Upvotes: 2