【问题标题】:Angular fullcalendar adding an event when clicking on the dayAngular fullcalendar 在点击当天添加一个事件
【发布时间】: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


【解决方案1】:

添加您的日历选项:

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' }
    ],
    dateClick:function (info) {
        console.log("See day infos: ",info);
    }
  };

我让你documentation 这里

【讨论】:

    猜你喜欢
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多