Articles in this section
Category / Section

How to get started easily with Syncfusion Angular 9 Calendar?

5 mins read

A quick start project that helps you to create an Angular 9 Calendar component with a minimal code configuration.

Angular 9 Calendar

The following section explains the steps required to create a simple Angular 9 Calendar component.

Pre-requisites

Make sure that you have the compatible versions of Angular in your machine before starting to work on this project.

Introduction

The Angular 9 Calendar used in this project is created from the Syncfusion ej2-angular-calendars package. You can simply define it as <ejs-calendar> within the template.

Dependencies

Before starting with this project, the Angular 9 Calendar requires to add the Syncfusion ej2-angular-calendars package from npmjs, which are distributed in npm as @syncfusion scoped packages.

Creating Angular Project

To create the Angular project using the Angular CLI tool, follow the given steps.

Install Angular CLI 9 using following command.

npm install -g @angular/cli@9.0.2

 

Note:

If you would like to follow and run the application in Angular8 or earlier version, you need to replace the CLI command version number with the corresponding angular version number.

 

npm install -g @angular/cli@<CLI VERSION>

 

Now, create a new Angular project by using the command ng new and navigate to that folder.

ng new <project name>
cd <project name>

 

Install the ej2-angular-calendars package through the npm install command.

npm install @syncfusion/ej2-angular-calendars --save

 

Adding Angular 9 Calendar with Min and Max

You can add the Angular 9 Calendar component by using ejs-calendar directive and the attributes within the tag allows you to define other functionalities.

Import the Calendar module into the Angular application (app.module.ts) from the ej2-angular-calendars package.

import {BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';
 
@NgModule({ 
    imports: [ BrowserModule, CalendarModule ],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ]
})
 
export class AppModule {}

 

Define the Angular Calendar code within the app.component.html file mapped against the templateUrl option in app.component.ts file.

Here, the Calendar component rendered with the min and max property

[app.component.ts]

import {Component} from '@angular/core';
 
@Component ({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
 
export class AppComponent {
    public minDate: Date = new Date ("05/07/2017");
    public maxDate: Date = new Date ("08/27/2017");
    public value: Date = new Date ("05/16/2017");
    constructor () {}
}

 

[app.component.html]

<ejs-calendar id=calendar [value]='value' [min]='minDate' [max]='maxDate'></ejs-calendar>

 

Refer to the CDN link of CSS reference within the index.html file.

[index.html]

<link href="https://cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/ej2-calendars/styles/material.css" rel="stylesheet" />

Run the application with the command ng serve and have a Calendar with min and max date will be displayed on the browser as shown below.                                                              

                                                  Calendar with min and max date in Angular 9 Calendar

Multi Selection

Calendar provides an option to select single or multiple dates or sequence of dates by using isMutiSelection and values properties. By default, isMultiSelection property will be in disabled state.

[app.component.ts]

import {Component} from '@angular/core';
 
@Component ({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
 
export class AppComponent {
    public value: Date [] = [new Date ("05/16/2017"), new Date ("05/12/2017"), new Date ("05/6/2017"), new Date ("05/26/2017"), new Date ("05/20/2017")]  
    public multiselect: Boolean = true;
    constructor () {}
}

 

 

[app.component.html]

<ejs-calendar id=calendar [values]='value' [isMultiSelection]='multiselect' ></ejs-calendar>

Run the ng serve command and have a Calendar with multiple values will be displayed on the browser as shown below.

                                                  Calendar with multiple values in Angular 9 Calendar

 Summary

Refer to our documentation and online samples for more features. If you have any queries, please let us know in the comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied