Skip to content

Commit eae5cf8

Browse files
authored
fix(material-experimental/mdc-form-field): avoid expression ch… (#18741)
There is currently a bug in the Angular Framework that results in ExpressionChangedAfterItHasBeenChecked errors not throwing when they should for OnPush components. Becuase we modify a variable used in the template after it was already checked (in ngAfterViewInit), we need to trigger change detection manually or the change might not be picked up.
1 parent e0634c9 commit eae5cf8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/material-experimental/mdc-form-field/form-field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
330330
this._refreshOutlineNotchWidth();
331331
// Enable animations now. This ensures we don't animate on initial render.
332332
this._subscriptAnimationState = 'enter';
333+
// Because the above changes a value used in the template after it was checked, we need
334+
// to trigger CD or the change might not be reflected if there is no other CD scheduled.
335+
this._changeDetectorRef.detectChanges();
333336
}
334337

335338
ngAfterContentInit() {

0 commit comments

Comments
 (0)