1

我正在我的 Angular 7 应用程序中实现 fullCalendar,日历正在工作,我正在向它导入一些事件,但我试图让它更有效,我试图只带来日历需要的事件。

所以..我有一些问题。

如何在 Prev 或 Next 或 Today 按钮中获取点击事件?

如何获取当前日期?

我一直在检查文档...但是只有 jquery 的示例...

在这里我复制我的 HTML

  <full-calendar id="calendar" *ngIf="options" #fullcalendar [editable]="true" [events]="citas"
    [header]="options.header" [locale]="options.locale" [customButtons]="options.customButtons"
    (dateClick)="dateClick($event)" [plugins]="options.plugins" (eventClick)="eventClick($event)" [eventLimit]="4">
  </full-calendar>

还有我的 T

  @ViewChild('fullcalendar') fullcalendar: FullCalendarComponent;

  constructor() {
    this.options = {

      editable: true,
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth, listDay'
      },
      plugins: [dayGridPlugin, listPlugin, timeGridPlugin],
      locale: esLocale,
    };

  }
4

2 回答 2

6

根据插件的文档,您可以访问Calendar原始数据和方法的底层对象:

const calendarApi = this.calendarComponent.getApi();

日期导航方法的完整列表可以在这里找到: https ://fullcalendar.io/docs/date-navigation 。

因此,要获取当前日期,我们可以使用:calendarApi.getDate();.

以下代码应该可以工作:

export class AppComponent {

  // references the #calendar in the template
  @ViewChild('calendar') calendarComponent: FullCalendarComponent;


  someMethod() {
    const calendarApi = this.calendarComponent.getApi();
    const currentDate = calendarApi.getDate();
    console.log("The current date of the calendar is " + currentDate);
  }
  
}

calendar.prev()我还没有发现任何为 prev 和 next 按钮发出的事件,但是您可以使用andcalendar.next()方法构建自己的按钮。

  goPrev() {
    const calendarApi = this.calendarComponent.getApi();
    calendarApi.next(); // call a method on the Calendar object
  }
于 2019-07-11T17:31:37.540 回答
1

我现在迟到了,但我想与您分享我的解决方案,所以:在您的 calendarOptions 中,您可以添加 customButtons 属性,然后将您的 newNextFunct 添加到 fullCalendar 函数,如下所示:

customButtons: {
    next: {
        click: this.nextMonth.bind(this),
    },
    prev: {
        click: this.prevMonth.bind(this),
    },
    today: {
        text: "Aujourd'hui",
        click: this.currentMonth.bind(this),
    },
},

你的 newNextFunction 命名为 nextMonth 必须是这样的:

nextMonth(): void {
    console.warn('nextMonth');
    this.calendarApi = this.calendarComponent.getApi();
    this.calendarApi.next();
}
于 2021-06-02T10:34:26.093 回答