Skip to content

Instantly share code, notes, and snippets.

@shah-smit
Last active March 7, 2017 03:07
Show Gist options
  • Save shah-smit/85aff341cd4a20494910ab2c17e82777 to your computer and use it in GitHub Desktop.
Save shah-smit/85aff341cd4a20494910ab2c17e82777 to your computer and use it in GitHub Desktop.
Getting Started with Angular 2 Full Calendar.

##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.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { RouterModule, Routes } from '@angular/router';
import { HttpModule } from '@angular/http';
import {AppRoutingModule, routableComponents } from './app-routing.module';
import { LoginService } from './login/login.service'
import { AzureService } from './services/azure.service'
import { PipeModule } from './app-pipe.module';
import { CalendarComponent } from './angular2-fullcalendar/src/calendar/calendar';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule,
PipeModule.forRoot()
],
declarations: [
AppComponent,
routableComponents,
CalendarComponent
],
providers: [
LoginService,
AzureService
],
bootstrap: [ AppComponent]
})
export class AppModule {
}
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
//For android Internet
'moment': 'npm:moment',
'jquery':'npm:jquery/dist/jquery.js',
'fullcalendar':'npm:fullcalendar/dist/fullcalendar.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
moment: { main: './moment.js', defaultExtension: 'js' }
}
});
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment