@@ -26,6 +26,7 @@ import {
2626 QueryList ,
2727 ViewChild ,
2828 ViewEncapsulation ,
29+ OnDestroy ,
2930} from '@angular/core' ;
3031import {
3132 CanColor , CanColorCtor ,
@@ -34,8 +35,8 @@ import {
3435 MAT_LABEL_GLOBAL_OPTIONS ,
3536 mixinColor ,
3637} from '@angular/material/core' ;
37- import { fromEvent , merge } from 'rxjs' ;
38- import { startWith , take } from 'rxjs/operators' ;
38+ import { fromEvent , merge , Subject } from 'rxjs' ;
39+ import { startWith , take , takeUntil } from 'rxjs/operators' ;
3940import { MatError } from './error' ;
4041import { matFormFieldAnimations } from './form-field-animations' ;
4142import { MatFormFieldControl } from './form-field-control' ;
@@ -141,9 +142,10 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
141142} )
142143
143144export class MatFormField extends _MatFormFieldMixinBase
144- implements AfterContentInit , AfterContentChecked , AfterViewInit , CanColor {
145+ implements AfterContentInit , AfterContentChecked , AfterViewInit , OnDestroy , CanColor {
145146 private _labelOptions : LabelOptions ;
146147 private _outlineGapCalculationNeeded = false ;
148+ private _destroyed = new Subject < void > ( ) ;
147149
148150 /** The form-field appearance style. */
149151 @Input ( )
@@ -303,6 +305,10 @@ export class MatFormField extends _MatFormFieldMixinBase
303305 this . _syncDescribedByIds ( ) ;
304306 this . _changeDetectorRef . markForCheck ( ) ;
305307 } ) ;
308+
309+ if ( this . _dir ) {
310+ this . _dir . change . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => this . updateOutlineGap ( ) ) ;
311+ }
306312 }
307313
308314 ngAfterContentChecked ( ) {
@@ -318,6 +324,11 @@ export class MatFormField extends _MatFormFieldMixinBase
318324 this . _changeDetectorRef . detectChanges ( ) ;
319325 }
320326
327+ ngOnDestroy ( ) {
328+ this . _destroyed . next ( ) ;
329+ this . _destroyed . complete ( ) ;
330+ }
331+
321332 /** Determines whether a class from the NgControl should be forwarded to the host element. */
322333 _shouldForward ( prop : keyof NgControl ) : boolean {
323334 const ngControl = this . _control ? this . _control . ngControl : null ;
0 commit comments