Skip to content

mat-button ExpressionChangedAfterItHasBeenCheckedError  #10914

@cec

Description

@cec

Bug:

Given 2 components: App and Sub where App has a reactive form containing

  • a checkbox
  • Sub component wrapped in a ngIf checking that the checkbox is checked
  • a submit button with [disabled]="form.invalid"

and Sub contains a required text input.

App.onInit defines a FormGroup containing only the checkbox.
Sub.onInit adds to the parent form a new FormGroup (parentFormDirective is injected with viewProvider)

All inputs have their matching material directives (e.g. mat-checkbox, mat-button, etc...")

When the checkbox is checked, ExpressionChangedAfterItHasBeenCheckedError is thrown.
If mat-button on the submit button is removed, the error is not thrown.

What is the expected behavior?

For ExpressionChangedAfterItHasBeenCheckedError to not be thrown.

What is the current behavior?

ExpressionChangedAfterItHasBeenCheckedError is thrown.

What are the steps to reproduce?

Sample project on github.
Created i StackBlitz, but got the following error when trying to save:
PATCH https://stackblitz.com/api/projects/angular-pc3way net::ERR_EMPTY_RESPONSE

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

Nesting inside parent forms reusable components that impact form-validity, is one of the fundamental features of a component-based framework. Having a material-styled button should not break this feature.

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

Angular
5.2.8
Material
5.2.5
OS
Windows 10
TypeScript
2.4.2

Is there anything else we should know?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions