##1: NPM Install##
npm install fullcalendar
npm i angular2-fullcalendar
npm install jquery
npm install moment
##2: Remove angular2-fullcalendar
from node_modules
and place it under app
folder##
##3: Open Systemjs.config.js
Add the below snippet end map
section.##
'moment': 'npm:moment',
'jquery':'npm:jquery/dist/jquery.js',
'fullcalendar':'npm:fullcalendar/dist/fullcalendar.js'
I have attached the file below for reference purpose only.
##4: Open app.module.ts
import CalendarComponent
from angular2-fullcalendar
##
import { CalendarComponent } from './angular2-fullcalendar/src/calendar/calendar';
Add the CalendarComponent
to declarations array.
@NgModule({
imports: [...],
declarations: [
CalendarComponent
],
providers: [...],
bootstrap: [...]
})
##5 Now its time to display the calendar. Pick your own component. For example, I will take booking.component.html
##
<angular2-fullcalendar [options]="calOptions" id="mycal" #mycal></angular2-fullcalendar>
In booking.component.ts
import { Options } from 'fullcalendar'
import * as $ from 'jquery';
import * as moment from "moment
Import the 3 things, now u see the importance the systemjs.config.js that we did earlier.
Contniue with booking.component.ts
in the class,
@ViewChild('mycal', { read: ElementRef }) myCal: ElementRef;
From the step 5 beginning, there is #mycal
in the html, that is 'mycal'
in the above statment.
calOptions: any = {};
Initialising the calOptions to be empty, remember not null.
Contructor()
{
var events = [ {
title: 'All Day Event',
start: '2016-09-01'
},
{
title: 'Long Event',
start: '2016-09-07',
end: '2016-09-10'
}];
this.UpdateCalendar(events);
}
UpdateCalendar(events)
{
this.calOptions.events = events
$(this.myCal.nativeElement).fullCalendar('addEventSource', events)
}
In the above, in constructor we have some events to be displayed, we are calling updateCalendar to update the events.