Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatSlideToggle: ngModel & [disabled] gives error #12323

Closed
vapits opened this issue Jul 23, 2018 · 2 comments · Fixed by #12325
Closed

MatSlideToggle: ngModel & [disabled] gives error #12323

vapits opened this issue Jul 23, 2018 · 2 comments · Fixed by #12325
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@vapits
Copy link

vapits commented Jul 23, 2018

Bug, feature request, or proposal:

Bug

What is the expected behavior?

ngModel should work with combination with disabled input.

What is the current behavior?

When I use a combination of those two and change the value of the disabled input on the update the I get an error in console (even that the component works correctly).

What are the steps to reproduce?

My DOM:

<mat-slide-toggle
   [(ngModel)]="item.enabled"
   (change)="updatePreference(item)"
   [disabled]="disableSwitches">
</mat-slide-toggle>

My component (the change event):

updatePreference(item: CommunicationPreferences) {
    this.disableSwitches = true;
    this.communicationPreferencesService.updatePreference(item)
    .finally(() => this.disableSwitches = false)
    .subscribe(data => {
      this.communicationPreferences.find(element => element.subscriptionId === item.subscriptionId).subscriptionId = data.subscriptionId;
    });
  }

The event works but the slide-toggle fails to come back from the disabled state and I get this error in the console:

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ng-untouched: true'. Current value: 'ng-untouched: false'.

Also here's a working link that can replicate the error: https://stackblitz.com/edit/angular-bn4cr8

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

Angular CLI: 6.0.7
Node: 9.8.0
OS: darwin x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser, router
... service-worker

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.6.7
@angular-devkit/build-angular       0.6.3
@angular-devkit/build-optimizer     0.6.3
@angular-devkit/core                0.0.22
@angular-devkit/schematics          0.0.39
@angular/cdk                        6.4.0
@angular/cli                        6.0.7
@angular/flex-layout                6.0.0-beta.15
@angular/material                   6.4.0
@angular/platform-browser-dynamic   6.0.0
@angular/pwa                        0.6.8
@ngtools/json-schema                1.1.0
@ngtools/webpack                    6.0.3
@schematics/angular                 0.6.0
@schematics/update                  0.6.7
rxjs                                6.2.1
typescript                          2.7.2
webpack                             4.10.2
@vapits vapits changed the title MatSlideToggle ngModel & disabled give error MatSlideToggle ngModel & [disabled] gives error Jul 23, 2018
@devversion devversion self-assigned this Jul 23, 2018
@devversion devversion changed the title MatSlideToggle ngModel & [disabled] gives error MatSlideToggle, MatCheckbox: ngModel & [disabled] gives error Jul 23, 2018
@devversion devversion changed the title MatSlideToggle, MatCheckbox: ngModel & [disabled] gives error MatSlideToggle: ngModel & [disabled] gives error Jul 23, 2018
@devversion
Copy link
Member

Thanks for the issue. Good catch. The same happens for the checkbox. Will create two separate PRs that solve that issue.

devversion added a commit to devversion/material2 that referenced this issue Jul 23, 2018
* Fixes that Angular throws an `ExpressionChangedAfterItHasBeenCheckedError` when disabling the slide-toggle while the component has been focused.

Fixes angular#12323
@devversion devversion added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jul 23, 2018
devversion added a commit to devversion/material2 that referenced this issue Jul 23, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related angular#12323
devversion added a commit to devversion/material2 that referenced this issue Jul 24, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related angular#12323
devversion added a commit to devversion/material2 that referenced this issue Jul 25, 2018
* Fixes that Angular throws an `ExpressionChangedAfterItHasBeenCheckedError` when disabling the slide-toggle while the component has been focused.

Fixes angular#12323
devversion added a commit to devversion/material2 that referenced this issue Jul 25, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related angular#12323
jelbourn pushed a commit that referenced this issue Aug 1, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related #12323
jelbourn pushed a commit that referenced this issue Aug 1, 2018
Fixes Angular throwing an `ExpressionChangedAfterItHasBeenCheckedError` when disabling the slide-toggle while the component has been focused.

Fixes #12323
jelbourn pushed a commit that referenced this issue Aug 7, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related #12323
jelbourn pushed a commit that referenced this issue Aug 7, 2018
Fixes Angular throwing an `ExpressionChangedAfterItHasBeenCheckedError` when disabling the slide-toggle while the component has been focused.

Fixes #12323
jelbourn pushed a commit that referenced this issue Aug 7, 2018
* Fixes that Angular throws an ExpressionChangedAfterItHasBeenCheckedError when disabling the checkbox while the component has been focused.
* Adds missing test for `NgModel` states after value change through view.

Related #12323
jelbourn pushed a commit that referenced this issue Aug 7, 2018
Fixes Angular throwing an `ExpressionChangedAfterItHasBeenCheckedError` when disabling the slide-toggle while the component has been focused.

Fixes #12323
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants