@@ -26,6 +26,7 @@ import {
26
26
QueryList ,
27
27
ViewChild ,
28
28
ViewEncapsulation ,
29
+ OnDestroy ,
29
30
} from '@angular/core' ;
30
31
import {
31
32
CanColor , CanColorCtor ,
@@ -34,8 +35,8 @@ import {
34
35
MAT_LABEL_GLOBAL_OPTIONS ,
35
36
mixinColor ,
36
37
} 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' ;
39
40
import { MatError } from './error' ;
40
41
import { matFormFieldAnimations } from './form-field-animations' ;
41
42
import { MatFormFieldControl } from './form-field-control' ;
@@ -141,9 +142,10 @@ export const MAT_FORM_FIELD_DEFAULT_OPTIONS =
141
142
} )
142
143
143
144
export class MatFormField extends _MatFormFieldMixinBase
144
- implements AfterContentInit , AfterContentChecked , AfterViewInit , CanColor {
145
+ implements AfterContentInit , AfterContentChecked , AfterViewInit , OnDestroy , CanColor {
145
146
private _labelOptions : LabelOptions ;
146
147
private _outlineGapCalculationNeeded = false ;
148
+ private _destroyed = new Subject < void > ( ) ;
147
149
148
150
/** The form-field appearance style. */
149
151
@Input ( )
@@ -303,6 +305,10 @@ export class MatFormField extends _MatFormFieldMixinBase
303
305
this . _syncDescribedByIds ( ) ;
304
306
this . _changeDetectorRef . markForCheck ( ) ;
305
307
} ) ;
308
+
309
+ if ( this . _dir ) {
310
+ this . _dir . change . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => this . updateOutlineGap ( ) ) ;
311
+ }
306
312
}
307
313
308
314
ngAfterContentChecked ( ) {
@@ -318,6 +324,11 @@ export class MatFormField extends _MatFormFieldMixinBase
318
324
this . _changeDetectorRef . detectChanges ( ) ;
319
325
}
320
326
327
+ ngOnDestroy ( ) {
328
+ this . _destroyed . next ( ) ;
329
+ this . _destroyed . complete ( ) ;
330
+ }
331
+
321
332
/** Determines whether a class from the NgControl should be forwarded to the host element. */
322
333
_shouldForward ( prop : keyof NgControl ) : boolean {
323
334
const ngControl = this . _control ? this . _control . ngControl : null ;
0 commit comments