Categories

Wednesday, January 8, 2025
#919814419350 therichposts@gmail.com
Angular 13FullCalendar

Angular 13 FullCalendar Working Demo with Dynamic Data

Angular 13 FullCalendar Working Demo with Dynamic Data

Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 13 FullCalendar Working Demo with Dynamic Data.

Angular Full Calendar
Angular 13 FullCalendar Working Demo with Dynamic Data
Angular 13 FullCalendar Working Demo with Dynamic Data
FullCalendar Dynamic Events Web API
FullCalendar Dynamic Events Web API

Angular12 came and if you are new then you must check below two links:

  1. Angular13 Tutorials
  2. Angular Free Templates

Guys if you want to update your Angular old version to Angular 13 then please click here.


Here is the code snippet and please use carefully:

1. Very first guys, here are common basics steps to add angular 13 application on your machine and also we must have latest nodejs version(14.17.0) installed for angular 13:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ npm install -g @angular/cli
$ ng new angularfullcalendar // Set Angular 13 Application on your pc
cd angularfullcalendar // Go inside project folder
$ npm install -g @angular/cli $ ng new angularfullcalendar // Set Angular 13 Application on your pc cd angularfullcalendar // Go inside project folder
$ npm install -g @angular/cli

$ ng new angularfullcalendar // Set Angular 13 Application on your pc

cd angularfullcalendar // Go inside project folder

2. Now run below commands to set fullcalendar modules into our angular 13 application:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
npm install --save @fullcalendar/angular @fullcalendar/daygrid
npm i @fullcalendar/interaction
npm install --save @fullcalendar/angular @fullcalendar/daygrid npm i @fullcalendar/interaction
npm install --save @fullcalendar/angular @fullcalendar/daygrid
npm i @fullcalendar/interaction

3. Now we will add below code into our angularfullcalendar/src/app/app.module.ts file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
...
import { HttpClientModule } from '@angular/common/http';
import { FullCalendarModule } from '@fullcalendar/angular';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
FullCalendarModule.registerPlugins([
dayGridPlugin,
interactionPlugin
]);
...
imports: [
...
FullCalendarModule,
HttpClientModule
],
...
... import { HttpClientModule } from '@angular/common/http'; import { FullCalendarModule } from '@fullcalendar/angular'; import dayGridPlugin from '@fullcalendar/daygrid'; import interactionPlugin from '@fullcalendar/interaction'; FullCalendarModule.registerPlugins([ dayGridPlugin, interactionPlugin ]); ... imports: [ ... FullCalendarModule, HttpClientModule ], ...
...
import { HttpClientModule } from '@angular/common/http';
import { FullCalendarModule } from '@fullcalendar/angular'; 
import dayGridPlugin from '@fullcalendar/daygrid'; 
import interactionPlugin from '@fullcalendar/interaction'; 
FullCalendarModule.registerPlugins([ 
  dayGridPlugin,
  interactionPlugin
]);
...
  imports: [
    ...
  FullCalendarModule,
  HttpClientModule
  ],
 ...

4. Now we will add below code into our angularfullcalendar/src/app/app.component.ts file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
...
import { HttpClient,HttpHeaders } from '@angular/common/http';
import { CalendarOptions } from '@fullcalendar/angular'; // useful for typechecking
export class AppComponent {
...
events = [];
calendarOptions: CalendarOptions;
constructor(private http:HttpClient) {}
ngOnInit(){
//web api calling to get dynamic events
this.http.get('http://localhost/events.php').subscribe(data => {
this.events.push(data);
console.log(this.events);
});
setTimeout(() => {
//full calendar setting and event binding
this.calendarOptions = {
initialView: 'dayGridMonth',
events: this.events[0]};
}, 1000);
}
}
... import { HttpClient,HttpHeaders } from '@angular/common/http'; import { CalendarOptions } from '@fullcalendar/angular'; // useful for typechecking export class AppComponent { ... events = []; calendarOptions: CalendarOptions; constructor(private http:HttpClient) {} ngOnInit(){ //web api calling to get dynamic events this.http.get('http://localhost/events.php').subscribe(data => { this.events.push(data); console.log(this.events); }); setTimeout(() => { //full calendar setting and event binding this.calendarOptions = { initialView: 'dayGridMonth', events: this.events[0]}; }, 1000); } }
...
import { HttpClient,HttpHeaders } from '@angular/common/http';
import { CalendarOptions } from '@fullcalendar/angular'; // useful for typechecking
export class AppComponent {
  ...
  events = [];
  calendarOptions: CalendarOptions;
  constructor(private http:HttpClient) {}
  
  ngOnInit(){

    //web api calling to get dynamic events
    this.http.get('http://localhost/events.php').subscribe(data => {
        this.events.push(data);
        console.log(this.events);
        
   });

   setTimeout(() => {

   //full calendar setting and event binding
    this.calendarOptions = {
        initialView: 'dayGridMonth',
        events: this.events[0]};
    }, 1000);
  }
}

5. Finally we will add below code into our angularfullcalendar/src/app/app.component.html file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<full-calendar [options]="calendarOptions"></full-calendar>
<full-calendar [options]="calendarOptions"></full-calendar>
<full-calendar [options]="calendarOptions"></full-calendar>

6. Guys in the end here is my `events.php` file code and this file is located in xampp/htdocs folder:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?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");
$events = array(
array('title' => 'Event 1','start' => '2021-05-25'), array('title' => 'Event 2','start' => '2021-05-26'),
array('title' => 'Event 3','start' => '2021-05-27'));
echo json_encode($events);
die();
?>
<?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"); $events = array( array('title' => 'Event 1','start' => '2021-05-25'), array('title' => 'Event 2','start' => '2021-05-26'), array('title' => 'Event 3','start' => '2021-05-27')); echo json_encode($events); die(); ?>
<?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");
   $events = array(
    array('title' => 'Event 1','start' => '2021-05-25'), array('title' => 'Event 2','start' => '2021-05-26'),
    array('title' => 'Event 3','start' => '2021-05-27'));
  
   echo json_encode($events);
   die();
   ?>

Now we are done friends and please run ng serve command to check output in browser(locahost:4200). If you have any kind of query then please do comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.

Jassa

Thanks

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.