@@ -31,6 +31,8 @@ import {MatMonthView} from './month-view';
31
31
import { MatMultiYearView , yearsPerPage } from './multi-year-view' ;
32
32
import { MatYearView } from './year-view' ;
33
33
import { ComponentPortal , ComponentType , Portal } from '@angular/cdk/portal' ;
34
+ import { Subject } from 'rxjs/Subject' ;
35
+ import { takeUntil } from 'rxjs/operators/takeUntil' ;
34
36
35
37
/** Default header for MatCalendar */
36
38
@Component ( {
@@ -41,15 +43,25 @@ import {ComponentPortal, ComponentType, Portal} from '@angular/cdk/portal';
41
43
preserveWhitespaces : false ,
42
44
changeDetection : ChangeDetectionStrategy . OnPush ,
43
45
} )
44
- export class MatCalendarHeader {
46
+ export class MatCalendarHeader implements OnDestroy {
47
+ /** Subject that emits when the component has been destroyed. */
48
+ private _destroyed = new Subject < void > ( ) ;
49
+
50
+ private _intlChanges : Subscription ;
51
+
45
52
constructor ( @Host ( ) public calendar : MatCalendar < any > ,
46
53
private _intl : MatDatepickerIntl ,
47
54
changeDetectorRef : ChangeDetectorRef ) {
55
+ this . _intlChanges = _intl . changes . pipe ( takeUntil ( this . _destroyed ) ) . subscribe (
56
+ ( ) => changeDetectorRef . markForCheck ( )
57
+ ) ;
58
+ }
48
59
49
- this . _intlChanges = _intl . changes . subscribe ( ( ) => changeDetectorRef . markForCheck ( ) ) ;
60
+ ngOnDestroy ( ) {
61
+ this . _destroyed . next ( ) ;
62
+ this . _destroyed . complete ( ) ;
50
63
}
51
64
52
- private _intlChanges : Subscription ;
53
65
}
54
66
55
67
/**
@@ -69,7 +81,6 @@ export class MatCalendarHeader {
69
81
changeDetection : ChangeDetectionStrategy . OnPush ,
70
82
} )
71
83
export class MatCalendar < D > implements AfterContentInit , OnDestroy , OnChanges {
72
-
73
84
/** An input indicating the type of the header component, if set. */
74
85
@Input ( ) headerComponent : ComponentType < any > ;
75
86
@@ -213,7 +224,6 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
213
224
}
214
225
215
226
ngAfterContentInit ( ) {
216
-
217
227
this . _calendarHeaderPortal = new ComponentPortal ( this . headerComponent || MatCalendarHeader ) ;
218
228
219
229
this . _activeDate = this . startAt || this . _dateAdapter . today ( ) ;
0 commit comments