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.

Mat-container id causes error: ExpressionChangedAfterItHasBeenCheckedError

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Mat-dialog opening up without warnings/error

What is the current behavior?

When a modal is open the following error is thrown:

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'id: undefined'. Current value: 'id: alert-dialog'. 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 ?

The error appears both when setting the id and when leaving it undefined so that an id is generated automatically.

What are the steps to reproduce?

StackBlitz repo, check the console after the modal appears: https://stackblitz.com/edit/angular-material2-issue-mat-container-id

What is the use-case or motivation for changing an existing behavior?

ExpressionChangedAfterItHasBeenCheckedError should not be thrown

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Error showing both with Angular 5.2.x and Angular/material 5.2.4, and with the latest v. 6 beta x as shown in the StackBlitz example.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
julianobrasilcommented, Apr 4, 2018

Have you tried calling your service method from inside a setTimeout()? Apparently, you’re generating the component too soon, before angular has finished it’s change detection cycle after the host component initialization. This is just a guess, I’m not sure about it. Try this: setTimeout(() => this.modalService.showAlert())

2reactions
ilDoncommented, Apr 5, 2018

@julianobrasil you are right, adding the timeout solves it. I’ve updated the example with two versions of the same modal, one with and one without the timeout, to show the difference.

Not sure if that should be fixed however, as calling a dialog withing ngOnInit might make sense in certain situations. Anyways in my case I’m calling it after an async check, so I’m good 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

težak Udružiti se sa pozdrav prekid crno pivo smetati mat dialog ...
pseudonim naučiti sto za posuđe Angular Debugging "Expression has changed": Explanation (and Fix) · dump opravdati profesor Mat-container id causes error: ...
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