在 fullcalendar.io Angular 打字稿中获取所选月份

Get the selected month in fullcalendar.io Angular typescript

我已经尝试使用 jquery 使用下面的代码,

  getMonth(){
    const date = $('#calendarOptions').fullCalendar('getCalendar');
    const monthInt = date.getMonth();
    // you now have the visible month as an integer from 0-11
 }

但是我收到一条错误消息,上面写着

Property 'fullCalendar' does not exist on type 'JQuery<HTMLElement>'.ts(2339)

有没有办法直接访问我当前使用打字稿的月份?

这个我也试过

getMonth(){
  const calendarApi = this.calendarOptions.getApi();
  const currentDate = calendarApi.view.currentStart;

  console.log(currentDate); // result: current calendar start date
}

但是,它说 属性 'getApi' 在类型 'CalendarOptions'

上不存在

尝试示例表格 Calendar API 部分(几乎是最后一个) https://fullcalendar.io/docs/angular

在下面添加此代码

    setTimeout(() => {
         const calendarApi = this.calendarComponent.getApi();
         const currentDate = calendarApi.view.currentStart;
      
         console.log(currentDate);
    }

这允许首先加载日历,然后您可以访问 getApi()。否则你会得到一个 ERROR TypeError: Cannot read 属性 'getApi' of undefined error message.