Search code examples
angularfullcalendarangular-clifullcalendar-4

Cannot get FullCalendar v4 to work with Angular and the Angular Cli


I'm trying to use FullCalendar v4 in an Angular 7 app using the angular cli and I'm getting Typescript errors during build as well as a console error in the browser stating that 'Calendar' is not defined. Not sure what I'm doing wrong as I seem to be following all directions. I've added this to a minimal angular application and added the files effected below bar the css but that shouldn't effect it.

Note - I've cloned this in a stackblitz example here and everything seems to work just fine but when recreating this locally several times in the angular cli I still get the same result.

https://stackblitz.com/edit/angular-lec711

package.json

{
  "name": "fullcalendar",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@fullcalendar/core": "4.0.0-beta.4",
    "@fullcalendar/resource-timegrid": "4.0.0-beta.4",
    "core-js": "^2.5.4",
    "n": "^2.1.12",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "~7.0.4",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  }
}

import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { Calendar } from '@fullcalendar/core';
import resourceTimeGridPlugin from '@fullcalendar/resource-timegrid';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
  @ViewChild('fullCalendarInstance') private fullCalendarInstance: any;
  ngAfterViewInit() {
    this.initFullCalendar();
  }

  initFullCalendar() {
    const calendar = new Calendar(this.fullCalendarInstance.nativeElement, {
      plugins: [resourceTimeGridPlugin],
      timeZone: 'UTC',
      defaultView: 'resourceTimeGridDay',
      groupByResource: true,
      resources: [
        { id: 'a', title: 'Room A' },
        { id: 'b', title: 'Room B' }
      ],
      events: 'https://fullcalendar.io/demo-events.json?with-resources=2'
    });

    calendar.render();
  }
}

<div #fullCalendarInstance></div>

enter image description here

enter image description here


Solution

  • I just updated my TypeScript in my package.json to "typescript": "~3.2.2" and I'm now able to build and not receive the error.