I recently reviewed some code where detectChanges()
is called from ngAfterViewChecked
. How does that not cause an infinite loop? Shouldn't it trigger another change detection cycle, which will call ngAfterViewChecked
again? Or does the change detection only apply to the view, and therefore ngAfterViewChecked
will only be called on the child components, not the host component?
Asked
Active
Viewed 681 times
3

Cory
- 51
- 2
1 Answers
0
You already answered it yourself: If you call detectChanges()
in a component, the change detection applies only to this view. You could theoretically cause an infinite loop by calling ApplicationRef.tick()
instead, which triggers change detection on the root, but Angular catches this and throws the error below:
A good deep-in-the-code overview of change detection is given in this article.

slim
- 414
- 1
- 7