Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击日期时添加事件的日历_Javascript_Angular_Fullcalendar_Fullcalendar 5 - Fatal编程技术网

Javascript 单击日期时添加事件的日历

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 = {

嗨,希望你能在这方面帮助我

我正在使用Angular 10和full calendar 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不是数组,因此我无法使用推送添加对象


如何添加它而不丢失第一个数据

您需要使用正确的函数将事件添加到日历中:谢谢您的回答,我发现了: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;