-1

I am new to angular 2. so, I don't know exactly how to use full calendar. if I use full calendar it shows full calendar is not a function. please help me. how to set it in angular2 from basic?

i am using this...

import {CalendarComponent} from "ap-angular2-fullcalendar";
Jay Patel
  • 305
  • 2
  • 6
  • 20

3 Answers3

1

Please install npm module

npm install --save angular-calendar

then import in both file in your index file

<link href="./node_modules/angular-calendar/dist/css/angular-calendar.css">
<script src="./node_modules/angular-calendar/dist/umd/angular-calendar.js"></script>

and

import module in module.ts file like

import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CalendarModule } from 'angular-calendar';

@NgModule({
  imports: [
    BrowserAnimationsModule,
    CalendarModule.forRoot()
  ]
})
export class MyModule {}

more information check below link & also work in angular 2.x version

https://www.npmjs.com/package/angular-calendar

Thanks,

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
1

Here is working plunker: http://plnkr.co/edit/eCypVy4l6H9SA9MNrm8w?p=preview

Steps:

  1. install npm package : npm install --save angular-calendar
  2. include css into your app: node_modules/angular-calendar/dist/css/angular-calendar.css
  3. import calendar module into your apps module:

    import { CalendarModule } from 'angular-calendar'; @NgModule({ imports: [ BrowserAnimationsModule, CalendarModule.forRoot() ] })

Here is working international calendar example:

component.ts:

import { Component, ChangeDetectionStrategy } from '@angular/core';
import {
  CalendarEvent,
  CalendarDateFormatter,
  DAYS_OF_WEEK
} from 'angular-calendar';
import { CustomDateFormatter } from './custom-date-formatter.provider';
@Component({
  selector: 'mwl-demo-component',
  changeDetection: ChangeDetectionStrategy.OnPush,
  templateUrl: 'template.html',
  providers: [
    {
      provide: CalendarDateFormatter,
      useClass: CustomDateFormatter
    }
  ]
})
export class DemoComponent {
  view: string = 'month';
  viewDate: Date = new Date();
  events: CalendarEvent[] = [];
  locale: string = 'fr';
  weekStartsOn: number = DAYS_OF_WEEK.MONDAY;
  weekendDays: number[] = [DAYS_OF_WEEK.FRIDAY, DAYS_OF_WEEK.SATURDAY];
}

template.html:

<mwl-demo-utils-calendar-header
  [(view)]="view"
  [(viewDate)]="viewDate"
  [locale]="locale">
</mwl-demo-utils-calendar-header>
<div [ngSwitch]="view">
  <mwl-calendar-month-view
    *ngSwitchCase="'month'"
    [viewDate]="viewDate"
    [events]="events"
    [locale]="locale"
    [weekStartsOn]="weekStartsOn"
    [weekendDays]="weekendDays">
  </mwl-calendar-month-view>
  <mwl-calendar-week-view
    *ngSwitchCase="'week'"
    [viewDate]="viewDate"
    [events]="events"
    [locale]="locale"
    [weekStartsOn]="weekStartsOn"
    [weekendDays]="weekendDays">
  </mwl-calendar-week-view>
  <mwl-calendar-day-view
    *ngSwitchCase="'day'"
    [viewDate]="viewDate"
    [events]="events"
    [locale]="locale">
  </mwl-calendar-day-view>
</div>

module.ts:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CalendarModule } from 'angular-calendar';
import { DemoUtilsModule } from '../demo-utils/module';
import { DemoComponent } from './component';
@NgModule({
  imports: [
    CommonModule,
    CalendarModule.forRoot(),
    DemoUtilsModule
  ],
  declarations: [DemoComponent],
  exports: [DemoComponent]
})
export class DemoModule {}

custom-date-formatter:

import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
import { getISOWeek } from 'date-fns';
export class CustomDateFormatter extends CalendarDateFormatter {
  public weekViewTitle({ date, locale }: DateFormatterParams): string {
    const year: string = new Intl.DateTimeFormat(locale, {
      year: 'numeric'
    }).format(date);
    const weekNumber: number = getISOWeek(date);
    return `Semaine ${weekNumber} en ${year}`;
  }
}
Vinko Vorih
  • 2,112
  • 2
  • 14
  • 22
0

You need to import,

import { CalendarModule } from "ap-angular2-fullcalendar";

as well

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { MaterializeModule } from 'angular2-materialize';
import { CalendarComponent } from "ap-angular2-fullcalendar";
import { AppComponent } from './app.component';
import { CalendarModule } from "ap-angular2-fullcalendar";

@NgModule({
  declarations: [
    AppComponent,
    CalendarComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • when I import CalendarModule in app.module.ts it gives me an error like this "Type CalendarComponent is part of the declarations of 2 modules: CalendarModule and AppModule! Please consider moving CalendarComponent to a higher module that imports CalendarModule and AppModule." – Jay Patel Oct 31 '17 at 05:09
  • look at this demo https://github.com/sajeetharan/ap-ng2-fullcalendar-demo – Sajeetharan Oct 31 '17 at 05:11
  • this is already done but the only problem is i cant use fullcalendar's event like addevents and change view and like this all. thanx for your great response... – Jay Patel Oct 31 '17 at 05:42
  • @Sajeetharan sir I 'm try your answer I had Following error https://stackoverflow.com/questions/47899427/fullcalendar-has-no-exported-member-options-getting-error-in-angular – core114 Dec 20 '17 at 12:00