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.

Expression has changed after it was checked for MatButton on disabled change through form validity change

See original GitHub issue

No error should arise!

When a dynamic input in a form changes its validity, Angular throws an exception.

Steps to reproduce:

https://stackblitz.com/edit/expression-was-checked-material Fill out Question, tick the extra check box, check the console for error logs: ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'disabled: false'. Current value: 'disabled: true'.

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

    "@angular/cdk": "7.3.2",
    "@angular/common": "^7.0.1",
    "@angular/core": "^7.0.1",
    "@angular/material": "^7.3.2"

Is there anything else we should know?

When there is no MatButton, there is no error.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
Iamakrcommented, Feb 18, 2019

@eydrian MatButton has nothing to do with this error, its because of the way angular’s change detection works in dev mode. Go through this Blog, this will help you understand, more about the error and will suggest some common approaches to tackle the error. Here’s one of the the ways to avoid this error Updated code on stackblitz

4reactions
exiledwolfkingcommented, Apr 10, 2019

Came across the same issue when the disabled logic of a field changes after an Observable/api return. Putting the timeout on the action that causes a change (in the observable subscribe) in the disabled logic worked for me as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NG0100: Expression has changed after it was checked - Angular
Angular throws an ExpressionChangedAfterItHasBeenCheckedError when an expression value has been changed after change detection has completed.
Read more >
Updating disabled status on a Reactive form not working ...
Problem Explanation. This error occurs if you update your UI after change detection has occurred. Lets try to follow what happens in your ......
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 >
[Part 4] Validate Table Rows and Fields with Angular Material
Learn how to validate table rows and input fields with Angular Material and HTML form validation.
Read more >
How to Set the disabled state in Angular Button component
To disable Button component, the disabled property can be set as true . The following example demonstrates button in disabled state. Source.
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