Professional Calendar for Angular
Angular 16+
npm i ng-pro-calendar
Import and inspect types
T_View
,T_Action
,Appointment
,Configs
,T_LANG
from ng-pro-calendar
Prop | Type | Required | Default |
---|---|---|---|
date |
string // iso string |
No | undefined |
view |
T_View |
No | "week" |
events |
Appointment[] |
No | [] |
loading |
boolean |
No | false |
config |
Configs |
No | DEFAULT_CONFIGS |
lang |
T_LANG |
No | only supported languages; default: undefined (the calendar will use browser locale). |
You can import
DEFAULT_CONFIGS
from ng-pro-calendar
When you set
nativeDatepicker
tofalse
orundefined
, Material DatePicker will be used.
When you set a property with type
T_Action
toundefined
, the action is disabled.
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ProCalendarModule } from 'ng-pro-calendar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ProCalendarModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component, OnInit } from '@angular/core';
import { Appointment, Configs, E_CustomEvents } from 'ng-pro-calendar';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'ng-pro-calendar';
evts: Appointment[] = [
{
date: "2022-11-24T16:00:50.253Z",
comment: "Faire une livraison à moto de Mont Sinaï à Calavi",
id: "cl3eddmjz1435801pqwfa5ihd1",
keywords: "Anniversaire",
name: "Rodolphe SOUNLIN",
},
{
date: "2022-11-19T14:00:00.000Z",
comment: "",
id: "cl32rbkjk1700101o53e3e3uhn",
keywords: "Projet BAMBA",
name: "MONTCHO Kévin",
},
{
date: "2022-11-17T13:00:36.284Z",
comment: "",
id: "cl34856g01439801piot8vp3jr",
keywords: "Rencontre",
name: "Cornelia ADADJO",
},
{
date: "2022-11-10T07:00:00.000Z",
comment: "",
id: "cl2yk477s136301pbmh49btdg",
keywords: "Anniversaire",
name: "Sylla Rahamata",
},
{
date: "2022-11-10T07:00:00.000Z",
comment: "",
id: "cl30h76qi116501nu2dc1wnv1",
keywords: "Réunion",
name: "Espéra AWO",
}
];
cfg: Configs = {
viewEvent: undefined,
reportEvent: {
icon: true,
text: "",
},
searchPlaceholder: "",
eventName: "",
closeText: "",
nativeDatepicker: false,
todayButton: true,
firstDayOfWeek: 1
};
ngOnInit(): void {
[E_CustomEvents.VIEW, E_CustomEvents.REPORT].forEach((e: string) => {
document.body.addEventListener(e, (event: Event | CustomEvent) => {
console.log({ event });
});
});
}
}
app.component.html
<pro-calendar
date="2022-11-10T00:00:00.000Z"
[events]="evts"
[config]="cfg"
/>
(calendarClosed)
:
This event is fired when user clicks close button.
(fetchEvents)
:
This event is fired when date selected changes.
$event: { start: string; end: string }
.start
andend
are iso string date.
Draw your own calendar using scoped slots
<pro-calendar
date="2022-11-10T00:00:00.000Z"
[events]="evts"
[config]="cfg"
>
<!-- <ng-template let-calendarGotLoading="calendarGotLoading" #loader> -->
<!-- content -->
<!-- </ng-template> -->
<!-- <ng-template #searchIcon> -->
<!-- dž -->
<!-- </ng-template> -->
<!-- <ng-template #leftSwitchArrow> -->
<!-- dž -->
<!-- </ng-template> -->
<!-- <ng-template #rightSwitchArrow> -->
<!-- dž -->
<!-- </ng-template> -->
<!-- <ng-template #closeButton> -->
<!-- dž -->
<!-- </ng-template> -->
<!-- <ng-template let-date="date" let-time="time" let-cardEvent="cardEvent" #eventCard> -->
<!-- use this template to show calendar event in appearance you want -->
<!--
date: Date;
time: string;
cardEvent: Appointment[]; // events according to date/time
-->
<!-- </ng-template> -->
<!-- <ng-template let-dateSelected="dateSelected" let-calendarEvents="calendarEvents" #sideEvent> -->
<!-- use this template to show side event in appearance you want -->
<!-- dateSelected: Date; -->
<!-- calendarEvents: Appointment[]; // all events -->
<!-- </ng-template> -->
</pro-calendar>
calendar.request.view
& calendar.request.report
When the user clicks on view or report action, a custom html event is fired with the id of event in detail. You can listen these events like described on Use.
On default
#sideEvent template
, when user clicks on event,calendar.request.view
is fired.