【发布时间】:2020-08-20 10:43:53
【问题描述】:
您好,希望您能帮我解决这个问题
我正在开发 Angular 10 和完整的日历 v5,我想知道如何在点击事件时将事件添加到当天
export class CalendarComponent implements OnInit{
nomaction;
constructor(public dialog: MatDialog) { }
ngOnInit(): void {
}
calendarOptions: CalendarOptions = {
initialView: 'dayGridMonth',
weekends: true,
dateClick: this.handleDateClick.bind(this), // bind is important!
events: [
{ title: 'event 1', date: '2020-08-20' },
{ title: 'event 2', date: '2020-08-21' }
]
};
handleDateClick(arg) {
const dialogRef = this.dialog.open(AddeventComponent, {
width: '250px',
data: {nomaction: this.nomaction}
});
dialogRef.afterClosed().subscribe(result => {
this.nomaction = result.nomaction;
this.calendarOptions.events = [{ title: this.nomaction, date: arg.dateStr }];//a code for adding an event into the day
console.log('action',this.nomaction);
});
}
toggleWeekends() {
this.calendarOptions.weekends = !this.calendarOptions.weekends
}
}
this.calendarOptions.events 不是数组,所以我不能使用 push 来添加对象!
如何在不丢失第一个数据的情况下添加它!
【问题讨论】:
-
您需要使用正确的函数将事件添加到日历中:fullcalendar.io/docs/Calendar-addEvent
-
谢谢你的回答,我找到了:calendar.addEvent(event [, source]) 但是我没有找到日历的类型,你知道如何实例化它吗?跨度>
-
它已经在文档中 - 请参阅“日历 API”部分下的 fullcalendar.io/docs/angular
-
“FullCalendarComponent”类型上不存在属性“addEvent”。 47 this.calendarComponent.addEvent({标题:this.nomaction,日期:arg.dateStr})
-
@ViewChild('calendar') calendarComponent: FullCalendarComponent;
标签: javascript angular fullcalendar fullcalendar-5