Description
Angular throws an ExpressionChangedAfterItHasBeenCheckedError
when an expression value has been changed after change detection has completed. Angular only throws this error in development mode.
In dev mode, Angular performs an additional check after each change detection run, to ensure the bindings haven’t changed. This catches errors where the view is left in an inconsistent state. This can occur, for example, if a method or getter returns a different value each time it is called, or if a child component changes values on its parent. If either of these occur, this is a sign that change detection is not stabilized. Angular throws the error to ensure data is always reflected correctly in the view, which prevents erratic UI behavior or a possible infinite loop.
This error commonly occurs when you’ve added template expressions or begun to implement lifecycle hooks like ngAfterViewInit
or ngOnChanges
. It is also common when dealing with loading status and asynchronous operations, or a child component changes its parent bindings.