Skip to content

Commit 050904b

Browse files
author
Tobias Schweizer
committed
refactor (custom header component): add test function to custom header component
1 parent f9628a8 commit 050904b

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

src/demo-app/datepicker/datepicker-demo.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,50 @@ import {MatCalendar} from '@angular/material';
1414

1515

1616
@Component({
17-
moduleId: module.id,
18-
selector: 'datepicker-demo',
19-
templateUrl: 'datepicker-demo.html',
20-
styleUrls: ['datepicker-demo.css'],
21-
changeDetection: ChangeDetectionStrategy.OnPush,
17+
moduleId: module.id,
18+
selector: 'datepicker-demo',
19+
templateUrl: 'datepicker-demo.html',
20+
styleUrls: ['datepicker-demo.css'],
21+
changeDetection: ChangeDetectionStrategy.OnPush,
2222
})
2323
export class DatepickerDemo {
24-
touch: boolean;
25-
filterOdd: boolean;
26-
yearView: boolean;
27-
inputDisabled: boolean;
28-
datepickerDisabled: boolean;
29-
minDate: Date;
30-
maxDate: Date;
31-
startAt: Date;
32-
date: Date;
33-
lastDateInput: Date | null;
34-
lastDateChange: Date | null;
35-
36-
dateFilter =
37-
(date: Date) => !(date.getFullYear() % 2) && (date.getMonth() % 2) && !(date.getDate() % 2)
38-
39-
onDateInput = (e: MatDatepickerInputEvent<Date>) => this.lastDateInput = e.value;
40-
onDateChange = (e: MatDatepickerInputEvent<Date>) => this.lastDateChange = e.value;
41-
42-
dateCtrl = new FormControl();
43-
44-
// pass custom header component type as input
45-
customHeader = CustomHeader;
24+
touch: boolean;
25+
filterOdd: boolean;
26+
yearView: boolean;
27+
inputDisabled: boolean;
28+
datepickerDisabled: boolean;
29+
minDate: Date;
30+
maxDate: Date;
31+
startAt: Date;
32+
date: Date;
33+
lastDateInput: Date | null;
34+
lastDateChange: Date | null;
35+
36+
dateFilter =
37+
(date: Date) => !(date.getFullYear() % 2) && (date.getMonth() % 2) && !(date.getDate() % 2)
38+
39+
onDateInput = (e: MatDatepickerInputEvent<Date>) => this.lastDateInput = e.value;
40+
onDateChange = (e: MatDatepickerInputEvent<Date>) => this.lastDateChange = e.value;
41+
42+
dateCtrl = new FormControl();
43+
44+
// pass custom header component type as input
45+
customHeader = CustomHeader;
4646
}
4747

4848
// Custom Header Component for DatePicker Calendar
4949
@Component({
5050
selector: 'custom-header',
51-
template: '<select><option>Gregorian</option><option>Julian</option></select>'
51+
template: '<select (change)="convertCalendarFormatTo($event.target.value)"><option>Gregorian</option><option>Julian</option></select>'
5252
})
5353
export class CustomHeader {
5454
constructor(@Host() public calendar: MatCalendar<any>,
5555
public adapter: DateAdapter<any>) {
56-
console.log(this.calendar);
57-
console.log(this.adapter);
56+
//console.log(this.calendar);
57+
//console.log(this.adapter);
58+
}
59+
60+
convertCalendarFormatTo(format: string) {
61+
console.log(format);
5862
}
5963
}

src/lib/datepicker/calendar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class MatCalendar<D> implements AfterContentInit, OnDestroy, OnChanges {
228228
this.calendarHeaderPortal = new ComponentPortal(DefaultHeader);
229229
}
230230

231-
console.log(this.calendarHeaderPortal)
231+
// console.log(this.calendarHeaderPortal)
232232

233233
this._activeDate = this.startAt || this._dateAdapter.today();
234234
this._focusActiveCell();

0 commit comments

Comments
 (0)