我正在使用 AngularCalendar,尤其是可点击的日子功能。当我登陆日历页面时,我需要显示选择的默认日期。当用户打开带有日历的页面时,他必须看到今天被选中。
如何创建新的 CalendarMonthViewDay 以便 Angular 可以看到它并在选定日期的情况下呈现页面?下面是我的代码
日期组件.ts
view: CalendarView = CalendarView.Month;
viewDate: Date = new Date();
actions: CalendarEventAction[] = [];
events: CalendarEvent[] = [];
selectedDay = null;
date = null;
dayClicked(event: any): void {
if (this.selectedDay != null) {
this.selectedDay.cssClass = "";
}
this.selectedDay = event.day;
this.selectedDay.cssClass = "cal-selected";
this.date = this.selectedDay.date;
console.log(this.date)
}
dateIsValid(date: Date): boolean {
return date.getTime() >= new Date().getTime();
}
beforeMonthViewRender({ body }: { body: CalendarMonthViewDay[] }): void {
body.forEach(day => {
if (!this.dateIsValid(day.date)) {
day.cssClass = 'cal-disabled';
}
});
}
date.component.html
<div class="calender-dates">
<mwl-calendar-month-view
id="calender1"
[viewDate]="viewDate"
[events]="events"
[refresh]="refresh"
(dayClicked)="dayClicked($event)"
(beforeViewRender)="beforeMonthViewRender($event)">
</mwl-calendar-month-view>
</div>
我已经尝试过了,但它也不起作用我还想要用户可以选择自定义日期的点击事件。
在此先感谢。任何帮助将不胜感激。