question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Opening MdDialog in ngOnInit throws ExpressionChangedAfterItHasBeenCheckedError

See original GitHub issue

Bug:

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:closed
  • Created 6 years ago
  • Reactions:20
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

41reactions
polottocommented, Jun 28, 2018

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 ?

24reactions
odahcamcommented, Aug 28, 2018

Another workaround is to put the dialog openning inside a setTimeout callback. e.g.:

  ngOnInit() {
    setTimeout(() => this.dialog.open(MyComponent))
  }

Also, openning the dialog in the construct works in my case.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found