在尝试导入插件 Angular 之前出现错误 fullcalendar lib

Mhm*_*adi 1 javascript types fullcalendar webpack angular

我有这个错误:

Error: Please import the top-level fullcalendar lib before attempting to import a plugin.
Run Code Online (Sandbox Code Playgroud)

当我将resourceTimeGridPlugin添加到插件中时。

我的代码:

import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin, { Draggable } from '@fullcalendar/interaction';
import { FullCalendarComponent } from '@fullcalendar/angular';
import timeGridPlugin from '@fullcalendar/timegrid';
import resourceTimeGridPlugin from '@fullcalendar/resource-timegrid';
Run Code Online (Sandbox Code Playgroud)

小智 5

您必须在组件中包含 Calendar Core 对象:

import { Calendar } from '@fullcalendar/core';
Run Code Online (Sandbox Code Playgroud)

在你的构造函数中你必须添加这个:

 constructor() { 
    const name = Calendar.name; 
 }
Run Code Online (Sandbox Code Playgroud)

完整示例:

import { Component } from '@angular/core';
import { Calendar } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  calendarOptions = {
    plugins: [dayGridPlugin],
    initialView: 'dayGridMonth'
  };

 constructor() { 
    const name = Calendar.name;
  }
}
Run Code Online (Sandbox Code Playgroud)

这会在插件需要之前强制加载/初始化核心组件和 VDom 引用。