首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何接下,prev,今天的事件与完整的日历角7 cli

如何接下,prev,今天的事件与完整的日历角7 cli
EN

Stack Overflow用户
提问于 2019-07-11 16:57:27
回答 2查看 8.5K关注 0票数 1

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

所以..。我有些问题要问。

如何在Prev或Next或can按钮中获得单击事件?

我怎样才能得到现在的日期?

我一直在查文件..。但是只有jquery的例子。

在这里我复制我的HTML

代码语言:javascript
运行
复制
  <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>

和我的Ts

代码语言:javascript
运行
复制
  @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,
    };

  }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-07-11 17:31:37

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

代码语言:javascript
运行
复制
const calendarApi = this.calendarComponent.getApi();

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

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

以下代码应该有效:

代码语言:javascript
运行
复制
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);
  }
  
}

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

代码语言:javascript
运行
复制
  goPrev() {
    const calendarApi = this.calendarComponent.getApi();
    calendarApi.next(); // call a method on the Calendar object
  }
票数 6
EN

Stack Overflow用户

发布于 2021-06-02 10:34:26

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

代码语言:javascript
运行
复制
customButtons: {
    next: {
        click: this.nextMonth.bind(this),
    },
    prev: {
        click: this.prevMonth.bind(this),
    },
    today: {
        text: "Aujourd'hui",
        click: this.currentMonth.bind(this),
    },
},

您的newNextFunction名为nextMonth,必须如下所示:

代码语言:javascript
运行
复制
nextMonth(): void {
    console.warn('nextMonth');
    this.calendarApi = this.calendarComponent.getApi();
    this.calendarApi.next();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56994088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档