fix(form-field): infinite loop with zone-patch-rxjs (#15335)

Fixes the form field being thrown into an infinite loop when `zone-patch-rxjs` is included in the page.

Fixes #15331.
This commit is contained in:
Kristiyan Kostadinov
2019-03-05 16:49:06 +01:00
committed by Joey Perrott
parent bc6b5fb3c4
commit 63cec8f8d6
+12 -5
View File
@@ -302,11 +302,18 @@ export class MatFormField extends _MatFormFieldMixinBase
// @breaking-change 7.0.0 Remove this check once _ngZone is required. Also reconsider
// whether the `ngAfterContentChecked` below is still necessary.
if (this._ngZone) {
this._ngZone.onStable.asObservable().pipe(takeUntil(this._destroyed)).subscribe(() => {
if (this._outlineGapCalculationNeededOnStable) {
this.updateOutlineGap();
}
const zone = this._ngZone;
if (zone) {
// Note that we have to run outside of the `NgZone` explicitly,
// in order to avoid throwing users into an infinite loop
// if `zone-patch-rxjs` is included.
zone.runOutsideAngular(() => {
zone.onStable.asObservable().pipe(takeUntil(this._destroyed)).subscribe(() => {
if (this._outlineGapCalculationNeededOnStable) {
this.updateOutlineGap();
}
});
});
}