Javascript 单击日期时添加事件的日历
嗨,希望你能在这方面帮助我 我正在使用Angular 10和full calendar v5,我想知道如何在单击时将事件添加到一天中Javascript 单击日期时添加事件的日历,javascript,angular,fullcalendar,fullcalendar-5,Javascript,Angular,Fullcalendar,Fullcalendar 5,嗨,希望你能在这方面帮助我 我正在使用Angular 10和full calendar v5,我想知道如何在单击时将事件添加到一天中 export class CalendarComponent implements OnInit{ nomaction; constructor(public dialog: MatDialog) { } ngOnInit(): void { } calendarOptions: CalendarOptions = {
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不是数组,因此我无法使用推送添加对象
如何添加它而不丢失第一个数据 您需要使用正确的函数将事件添加到日历中:谢谢您的回答,我发现了:calendar.addEvent(event[,source]),但我没有找到日历的类型,您知道如何实例化它吗?它已经在文档中了-请参阅“calendar API”部分下的类型“FullCalendarComponent”上不存在属性“addEvent”。47 this.calendarComponent.addEvent({title:this.noAction,date:arg.dateStr})@ViewChild('calendar')calendarComponent:FullCalendarComponent;您需要使用正确的函数将事件添加到日历中:谢谢您的回答,我发现了:calendar.addEvent(event[,source]),但我没有找到日历的类型,您知道如何实例化它吗?它已经在文档中了-请参阅“calendar API”部分下的类型“FullCalendarComponent”上不存在属性“addEvent”。47 this.calendarComponent.addEvent({title:this.noAction,date:arg.dateStr})@ViewChild('calendar')calendarComponent:FullCalendarComponent;