ExpressionChangedAfterItHasBeenCheckedError Explained
I had a similar issue. Looking at the lifecycle hooks documentation, I changed ngAfterViewInit
to ngAfterContentInit
and it worked.
This error indicates a real problem in your application, therefore it makes sense to throw an exception.
In devMode
change detection adds an additional turn after every regular change detection run to check if the model has changed.
If the model has changed between the regular and the additional change detection turn, this indicates that either
- change detection itself has caused a change
- a method or getter returns a different value every time it is called
which are both bad, because it is not clear how to proceed because the model might never stabilize.
If Angular runs change detection until the model stabilizes, it might run forever. If Angular doesn't run change detection, then the view might not reflect the current state of the model.
See also What is difference between production and development mode in Angular2?