I installed FullCalendar 5 in my Angular 9 project
then I get this error in the console of browser and anything appears in the page
vdom.js:3 Uncaught Error: Please import the top-level full calendar lib before attempting to import a plugin.
at Module../node_modules/@fullcalendar/common/vdom.js (vdom.js:3)
at __webpack_require__ (bootstrap:79)
at Module../node_modules/@fullcalendar/common/main.js (main.js:1)
at __webpack_require__ (bootstrap:79)
at Module../node_modules/@fullcalendar/daygrid/main.js (main.js:1)
at __webpack_require__ (bootstrap:79)
at Module../src/app/demo/demo.component.ts (demo.component.ts:1)
at __webpack_require__ (bootstrap:79)
at Module../src/app/Modules/app-routing.module.ts (app-routing.module.ts:1)
at __webpack_require__ (bootstrap:79)
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FullCalendarModule } from '@fullcalendar/angular'; // for FullCalendar!
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FullCalendarModule // for FullCalendar!
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/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'
};
}
<full-calendar [options]="calendarOptions"></full-calendar>
For fixing this issue you need to import calendar core library at the top, then you need to initialize core lib in your constructor like this
import { Component } from '@angular/core';
import { Calendar } from '@fullcalendar/core'; // include this line
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; // add this line in your constructor
}
}
There is a better way to deal with this:
Register your plugins in app.modules.ts:
import resourceTimeGridPlugin from '@fullcalendar/resource-timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import bootstrapPlugin from '@fullcalendar/bootstrap';
FullCalendarModule.registerPlugins([ // register FullCalendar plugins
dayGridPlugin,
interactionPlugin,
bootstrapPlugin
]);
...
But in calenderOptions, you have to remove plugin property:
calendarOptions = {
- plugins: [ dayGridPlugin, interactionPlugin, bootstrapPlugin],
initialView: 'dayGridMonth',
...
}
I got the same issue and fixed it by changing the order of the import libraries. What I did was FullCalendarModule
library imported before the component in the module.ts
like this below:
import { FullCalendarModule } from '@fullcalendar/angular';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import { MycalendarComponent } from './mycalendar/mycalendar.component';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With