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



我已经尝试使用以下代码使用 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"在类型"日历选项"上不存在

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

在下面添加此代码

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

console.log(currentDate);
}

这允许日历首先加载,然后您可以访问getApi()。 否则,您最终会得到错误类型错误:无法读取未定义错误消息的属性"getApi"。

最新更新