【问题标题】:Angular 10 FullCalendar Rest Api No jQueryAngular 10 FullCalendar Rest Api 没有 jQuery
【发布时间】:2021-05-20 13:03:43
【问题描述】:

如何将事件放入日历中?

HTML

<full-calendar #calendar [options]="calendarOptions"></full-calendar>

TS

export class AppComponent implements OnInit {

  constructor(
    private vacationService: VacationService,
  ) {}

  ngOnInit(): void {
    this.loadEvents();
  }

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

  calendarOptions: CalendarOptions = {
    initialView: 'dayGridMonth',
    headerToolbar: { 
      left: '',
      center: 'title',
    },
    editable: true,   
  
  };

  loadEvents(): void {
      this.vacationService.getAll().subscribe((data) => {
        // My data
        console.log(data);
      })
  }
}

这是我的 Api 响应

(1) [{…}] 0: 日期:“2018-03-29T13:34:00.000+0200” holidayGR: {id: 21, holiday: "First Event"} 编号:7 原型:对象

有什么帮助吗?或工作示例?谢谢

【问题讨论】:

    标签: angular fullcalendar fullcalendar-4


    【解决方案1】:

    calendarOptions 对象有一个 events 属性,您可以在其中添加事件。只需尝试将其添加到您的 AppComponent。

    calendarOptions: CalendarOptions = {
      initialView: 'dayGridMonth',
      dateClick: this.handleDateClick.bind(this), // bind is important!
      events: [ // <= here
        { title: 'event 1', date: '2019-04-01' },
        { title: 'event 2', date: '2019-04-02' }
      ]
    };
    

    复制自FullCalendar Docs 无需访问@ViewChild 即可更改事件

    您的加载事件可能看起来像这样。我不知道你的数据是怎么定义的。

    loadEvents(): void {
      this.vacationService.getAll().subscribe((data) => {
        this.calendarOptions.events = data.map(
          evt => {
            return { date: evt.date, title: evt.holidayGR.holiday }
          })
      })
    }
    

    【讨论】:

    • 我需要从我的 BD 中恢复 50 个事件。
    • 您需要将数据处理为标题日期格式并将其添加到事件数组中,例如:this.calendaroptions.events.push({title: "bla", date:.. . })
    • 你能做一个简短的例子吗?
    猜你喜欢
    • 2020-12-23
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2021-12-09
    • 1970-01-01
    • 2011-12-04
    相关资源
    最近更新 更多