我也遇到过这个问题。这是一个解决方案(这里我使用 moment.js。Date 也可以)
HTML
<mat-calendar #smallCalendar
[startAt]="smallCalendarStartAt"
[selected]="smallCalendarSelected">
</mat-calendar>
打字稿
// Small calendar properties
@ViewChild('smallCalendar', { static: false }) smallCalendar: MatCalendar<Date>;
smallCalendarStartAt: Date;
smallCalendarSelected: any;
// Refresh the small calendar
this.smallCalendarStartAt = new Date(moment().year(), +moment().format('MM'), +moment().format('DD'));
this.smallCalendarSelected = this.smallCalendarStartAt; // Update the selected day in mat-calendar
this.smallCalendar._goToDateInView(this.smallCalendarStartAt, 'month'); // Update the month in the mat-calendar
您可以调整变量 smallCalendarStartAt。这里以实际月份的日期为例,只会切换到下个月
这是一个带有日期函数的演示:DEMO