Angular 14 FullCalendar Dynamic Events Example

Angular 14 FullCalendar Dynamic Events Example

Angular 14 fullcalendar integration with dynamic events. In this tutorial, we will learn how to integrate fullcalendar in angular 14 apps and display dynamic data or events into the fullcalendar.

Angular 14 FullCalendar Dynamic Events Example

Use the following steps and integrate fullcalendar and display dynamic event fullcalendar in angular 14 apps:

  • Step 1 – Create New Angular App
  • Step 2 – Install FullCalendar Library
  • Step 3 – Add Code on App.Module.ts File
  • Step 4 – Add Code on View File
  • Step 5 – Add Code On app.Component ts File
  • Step 6 – Create Dynamic Events in Angular
  • Step 7 – Start the Angular App

Step 1 – Create New Angular App

First of all, open your terminal and execute the following command on it to install angular app:

ng new my-new-app

Step 2 – Install FullCalendar Library

Then install NPM package called @fullcalendar/angular to implement fullcalendar in angular apps. So, You can install the packages by executing the following commands on the terminal:

 npm install @fullcalendar/angular 
 npm install @fullcalendar/daygrid
 npm install @fullcalendar/interaction

Step 3 – Add Code on App.Module.ts File

Visit src/app directory and open app.module.ts file. And then add the following lines of into app.module.ts file:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

// import modules
import { HttpClientModule } from '@angular/common/http';

import { FullCalendarModule } from '@fullcalendar/angular'; 
import interactionPlugin from '@fullcalendar/interaction';
import dayGridPlugin from '@fullcalendar/daygrid';

FullCalendarModule.registerPlugins([ 
  interactionPlugin,
  dayGridPlugin
]);

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FullCalendarModule,
    HttpClientModule    
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

Step 4 – Add Code on View File

Create fullcalendar in angular 14 app. So, visit src/app/ and app.component.html and update the following code into it:

<div class="container">
  <full-calendar [options]="calendarOptions"></full-calendar>
</div>

Step 5 – Add Code On app.Component ts File

Visit the src/app directory and open app.component.ts. Then add the following code into component.ts file:

import { Component } from '@angular/core';

import { HttpClient } from '@angular/common/http';
import { CalendarOptions } from '@fullcalendar/angular';

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

export class AppComponent {

    Events = [];
    calendarOptions: CalendarOptions;
    
    constructor(private httpClient: HttpClient) { }

    onDateClick(res) {
      alert('Clicked on date : ' + res.dateStr)
    }

    ngOnInit(){
      setTimeout(() => {
        return this.httpClient.get('http://localhost:8888/event.php')
          .subscribe(res => {
              this.Events.push(res);
              console.log(this.Events);
          });
      }, 2200);

      setTimeout(() => {
        this.calendarOptions = {
          initialView: 'dayGridMonth',
          dateClick: this.onDateClick.bind(this),
          events: this.Events
        };
      }, 2500);
          
      }  

}

Step 6 – Create Dynamic Events in Angular

Create event.php file and update the following code in the file:

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

$calendarEvents = array('title' => 'Event name', 'start' => '2021-05-10');

echo json_encode($calendarEvents);

Step 7 – Start the Angular App

Execute the following command on terminal to start angular fullcalendar npm app:

ng serve

Recommended Angular Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *