Skip to content

Commit a88fecb

Browse files
author
Tobias Schweizer
committed
fix (MatCalendar): clean stream up after component destruction
1 parent 57bd12c commit a88fecb

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/lib/datepicker/calendar.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {MatMonthView} from './month-view';
3131
import {MatMultiYearView, yearsPerPage} from './multi-year-view';
3232
import {MatYearView} from './year-view';
3333
import {ComponentPortal, ComponentType, Portal} from '@angular/cdk/portal';
34+
import {Subject} from 'rxjs/Subject';
35+
import {takeUntil} from 'rxjs/operators/takeUntil';
3436

3537
/** Default header for MatCalendar */
3638
@Component({
@@ -41,15 +43,25 @@ import {ComponentPortal, ComponentType, Portal} from '@angular/cdk/portal';
4143
preserveWhitespaces: false,
4244
changeDetection: ChangeDetectionStrategy.OnPush,
4345
})
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+
4552
constructor(@Host() public calendar: MatCalendar<any>,
4653
private _intl: MatDatepickerIntl,
4754
changeDetectorRef: ChangeDetectorRef) {
55+
this._intlChanges = _intl.changes.pipe(takeUntil(this._destroyed)).subscribe(
56+
() => changeDetectorRef.markForCheck()
57+
);
58+
}
4859

49-
this._intlChanges = _intl.changes.subscribe(() => changeDetectorRef.markForCheck());
60+
ngOnDestroy() {
61+
this._destroyed.next();
62+
this._destroyed.complete();
5063
}
5164

52-
private _intlChanges: Subscription;
5365
}
5466

5567
/**
@@ -69,7 +81,6 @@ export class MatCalendarHeader {
6981
changeDetection: ChangeDetectionStrategy.OnPush,
7082
})
7183
export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
72-
7384
/** An input indicating the type of the header component, if set. */
7485
@Input() headerComponent: ComponentType<any>;
7586

@@ -213,7 +224,6 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
213224
}
214225

215226
ngAfterContentInit() {
216-
217227
this._calendarHeaderPortal = new ComponentPortal(this.headerComponent || MatCalendarHeader);
218228

219229
this._activeDate = this.startAt || this._dateAdapter.today();

src/lib/datepicker/datepicker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ export class MatDatepickerContent<D> extends _MatDatepickerContentMixinBase
134134
changeDetection: ChangeDetectionStrategy.OnPush,
135135
encapsulation: ViewEncapsulation.None,
136136
})
137-
138137
export class MatDatepicker<D> implements OnDestroy, CanColor {
139-
140138
/** An input indicating the type of the custom header component for the calendar, if set. */
141139
@Input() calendarHeaderComponent: ComponentType<any>;
142140

0 commit comments

Comments
 (0)