FullCalendar Angular Component

repository·main·Indexed 22 days ago

https://github.com/fullcalendar/fullcalendar-angular

The official Angular component for FullCalendar (version 6.1.21), providing a bridge between Angular applications and the FullCalendar core library. It features the <full-calendar> component, support for Angular versions 12 through 22, and customizable rendering via nested templates such as #eventContent. The component allows configuration through a CalendarOptions object or specific inputs like events, eventSources, and resources, and provides access to the underlying API via the getApi() method.

Tokens
2.5K
Snippets
11
Records
12
Agent score
78%

What's inside @fullcalendar/angular

  1. Register FullCalendarModule in your Angular app

    main

    Before using the component, you must import FullCalendarModule into your application's module (usually AppModule).

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FullCalendarModule } from '@fullcalendar/angular';
    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        FullCalendarModule // register FullCalendar with your app
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
  2. Install the FullCalendar Angular component

    main

    To use FullCalendar in an Angular application, you must install the Angular connector (@fullcalendar/angular), the core engine (@fullcalendar/core), and the specific plugins you intend to use (e.g., @fullcalendar/daygrid).

    npm install @fullcalendar/angular @fullcalendar/core @fullcalendar/daygrid
  3. Import FullCalendarModule into your Angular application

    main

    To use the FullCalendar component in your Angular application, you must import the FullCalendarModule into your component's module or standalone component. This module exports the FullCalendarComponent, which is the primary entry point for rendering a calendar.

    import { FullCalendarModule } from '@fullcalendar/angular';
    
    @NgModule({
      imports: [
        FullCalendarModule
        // ... other imports
      ],
      // ...
    })
    export class MyModule { }
  4. Use the <full-calendar> component

    main

    Once registered, use the <full-calendar> component in your templates. You must bind an [options] property to an object of type CalendarOptions. This object configures plugins, views, and event data.

    import { Component } from '@angular/core';
    import { CalendarOptions } from '@fullcalendar/core';
    import dayGridPlugin from '@fullcalendar/daygrid';
    
    @Component({
      selector: 'app-root',
      templateUrl: `
        <div>
          <h1>Demo App</h1>
          <full-calendar [options="calendarOptions"></full-calendar>
        </div>
      `,
      styleUrls: ['./app.component.scss']
    })
    export class AppComponent {
      calendarOptions: CalendarOptions = {
        plugins: [dayGridPlugin],
        initialView: 'dayGridMonth',
        weekends: false,
        events: [
          { title: 'Meeting', start: new Date() }
        ]
      };
    }
  5. Customize event rendering with nested templates

    main

    You can customize how specific parts of the calendar are rendered by providing nested Angular templates inside the <full-calendar> component. For example, use #eventContent to customize the appearance of event elements.

    <full-calendar [options="calendarOptions">
      <ng-template #eventContent let-arg>
        <b>{{arg.timeText}}</b>
        <i>{{arg.event.title}}</i>
      </ng-template>
    </full-calendar>
  6. Deep change detection for FullCalendar Angular options

    main

    The FullCalendar Angular component uses deep change detection for specific configuration properties to ensure updates are correctly reflected in the underlying FullCalendar instance. When these properties change, the component performs a deep comparison rather than a simple reference check.

    The following options are subject to deep change detection:

    • headerToolbar
    • footerToolbar
    • events
    • eventSources
    • resources
    // Options subject to deep change detection:
    // headerToolbar, footerToolbar, events, eventSources, resources
  7. Customize Calendar rendering with Templates

    main

    You can customize the appearance of specific parts of the calendar by providing Angular templates using @ContentChild template references. These templates allow you to inject custom HTML/Angular logic into the calendar's internal rendering slots.

    Available template names include:

    • dayHeaderContent: Content for day headers.
    • dayCellContent: Content for day cells.
    • weekNumberContent: Content for week numbers.
    • nowIndicatorContent: Content for the 'now' indicator.
    • eventContent: Content for events.
    • slotLaneContent: Content for slot lanes.
    • slotLabelContent: Content for slot labels.
    • allDayContent: Content for all-day sections.
    • moreLinkContent: Content for the 'more' link.
    • noEventsContent: Content shown when no events are present.
    • resourceAreaHeaderContent: Header for the resource area.
    • resourceGroupLabelContent: Label for resource groups.
    • resourceLabelContent: Label for individual resources.
    • resourceLaneContent: Content for resource lanes.
    • resourceGroupLaneContent: Content for resource group lanes.
    <full-calendar [options="calendarOptions">
      <!-- Customizing event content -->
      <ng-template #eventContent="templateRef" let-event>
        <b>{{ event.title }}</b>
        <em class="secondary">{{ event.extendedProps.description }}</em>
      </ng-template>
    
      <!-- Customizing day cell content -->
      <ng-template #dayCellContent="templateRef" let-date>
        {{ date.dayNumber }}
      </ng-template>
    </full-calendar>
  8. Configure FullCalendar via Input properties

    main

    The component accepts several inputs to control its behavior and data:

    • options: A CalendarOptions object containing the full configuration for the calendar.
    • deepChangeDetection: A boolean that, when enabled, allows the component to perform deep equality checks on complex option objects to detect changes.
    • events: A specific input for providing event data.
    • eventSources: A specific input for providing event sources.
    • resources: A specific input for providing resource data (used in resource-based views).

    Note: Individual inputs like events and resources will be merged into the main options object.

    // Example of the types used for inputs
    import { CalendarOptions } from '@fullcalendar/core';
    
    // In your component class:
    calendarOptions: CalendarOptions = {
      initialView: 'dayGridMonth',
      // ... other options
    };
    
    // Or using individual inputs in template:
    // <full-calendar [options="calendarOptions"></full-calendar>
  9. Access the FullCalendar API instance

    main

    To interact directly with the underlying FullCalendar instance (e.g., to call methods like .next(), .prev(), or .refetchEvents()), use the getApi() method on the FullCalendarComponent instance.

    // In your Angular component
    @ViewChild('calendar') calendarComponent!: FullCalendarComponent;
    
    nextMonth() {
      const calendarApi = this.calendarComponent.getApi();
      calendarApi.next();
    }
  10. Use the FullCalendar Angular Component

    main

    The FullCalendarComponent (selector: full-calendar) is the primary way to integrate FullCalendar into an Angular application. You can configure the calendar using a single options object or by using specific individual @Input properties for common data like events, eventSources, and resources.

    <!-- Basic usage with options object -->
    <full-calendar [options="calendarOptions"></full-calendar>
    
    <!-- Usage with individual inputs -->
    <full-calendar 
      [events="myEvents" 
      [eventSources="mySources" 
      [resources="myResources">
    </full-calendar>
  11. Input properties for FullCalendar Angular component

    main

    The FullCalendar Angular component exposes the following primary input properties for data binding. These properties allow you to pass calendar data directly into the component:

    • events: An array or object defining the events to be displayed.
    • eventSources: An array of event sources.
    • resources: An array of resources used for scheduling (e.g., in resource-based views).
    // Available @Input() names:
    // 'events'
    // 'eventSources'
    // 'resources'