Skip to content

Commit 515cc06

Browse files
mmalerbajelbourn
authored andcommitted
fix(form-field): run change detection when prefix or suffix changes (#10670)
1 parent 95dba59 commit 515cc06

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/lib/form-field/form-field.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
MAT_LABEL_GLOBAL_OPTIONS,
3434
mixinColor,
3535
} from '@angular/material/core';
36-
import {fromEvent} from 'rxjs';
36+
import {EMPTY, fromEvent, merge} from 'rxjs';
3737
import {startWith, take} from 'rxjs/operators';
3838
import {MatError} from './error';
3939
import {matFormFieldAnimations} from './form-field-animations';
@@ -246,12 +246,10 @@ export class MatFormField extends _MatFormFieldMixinBase
246246
this._changeDetectorRef.markForCheck();
247247
});
248248

249-
let ngControl = this._control.ngControl;
250-
if (ngControl && ngControl.valueChanges) {
251-
ngControl.valueChanges.subscribe(() => {
252-
this._changeDetectorRef.markForCheck();
253-
});
254-
}
249+
// Run change detection if the value, prefix, or suffix changes.
250+
const valueChanges = this._control.ngControl && this._control.ngControl.valueChanges || EMPTY;
251+
merge(valueChanges, this._prefixChildren.changes, this._suffixChildren.changes)
252+
.subscribe(() => this._changeDetectorRef.markForCheck());
255253

256254
// Re-validate when the number of hints changes.
257255
this._hintChildren.changes.pipe(startWith(null)).subscribe(() => {

0 commit comments

Comments
 (0)