Opening MdDialog in ngOnInit throws ExpressionChangedAfterItHasBeenCheckedError
See original GitHub issueBug:
When opening a MdDialog
inside ngOnInit
of a component a ExpressionChangedAfterItHasBeenCheckedError
error is thrown. If the MdDialog
is opened in the constructor of a component no error is thrown.
Temp workaround is to open the MdDialog
inside a setTimeout(() => this._dialog.open(MyComponent))
What are the steps to reproduce?
http://plnkr.co/edit/aE6LNzRVYnKB01bMej87?p=preview
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
This only seems occur with material-beta.7 and angular 4.2.0+.
Works fine with material-beta.7 and angular 4.1.3.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:20
- Comments:16 (5 by maintainers)
Top Results From Across the Web
MdDialog and ExpressionChangedAfterItHasBeenCheckedError
My problem is that I always get this error when I open the dialog: "Expression has changed after it was checked. Previous value:...
Read more >Mat Dialog Error in Angular Component ... - Stack Overflow
I experienced this same underlying issue with the following error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it ...
Read more >ExpressionChangedAfterItHasBe...
The ExpressionChangedAfterItHasBeenCheckedError error is thrown up when the binding expression changes after being checked by Angular during ...
Read more >angular/angular - Gitter
each child has an ngOnInit() that registers it to the parent, ... is that I'm getting the ExpressionChangedAfterItHasBeenCheckedError :(.
Read more >Angular Debugging "Expression has changed": Explanation ...
Learn a complete explanation about ExpressionChangedAfterItHasBeenCheckedError: why it occurs, how to troubleshoot it and how to fix it.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem here when I tried open the MatDialog:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'id: undefined'. Current value: 'id: mat-dialog-0'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
Another workaround is to put the dialog openning inside a
setTimeout
callback. e.g.:Also, openning the dialog in the
construct
works in my case.