How to Use Calendar Component in Angular Application
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (919)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (150)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Getting started with Angular Calendar component

How to Use Calendar Component in Angular Application

In this blog post, we are going to see how to use the Calendar component in an Angular application. You will learn how to get started with a simple Calendar component and how to enable several of its features by extending the sample with simple code snippets.

The Angular Calendar is a form component that displays the date and days of the week for Gregorian and Islamic calendars. It provides month, year, and decade view options to navigate quickly to the desired date. This component is typically used in an application when you handle date-related operations like appointment scheduling.

Getting started with the Calendar component

The following steps guide you through the necessary configuration for the Calendar component in an Angular 8 application using the Angular CLI tool.

  1. Use the following command to install the latest Angular CLI (8) locally in your application.
    npm install -g @angular/cli@latest

    Note: If you want to follow and run the application in Angular 7, Angular 6, Angular 5, or Angular 4, you need to replace the CLI command version number with the corresponding Angular version number.

    npm install -g @angular/cli@<CLI VERSION>
  2. Now, create a new Angular project using the command ng new and navigate to that folder.
    ng new <Simple Calendar >
    cd <Simple Calendar >
    
  3. Use the following command to install the ej2-angular-calendars package locally in your application.
    npm install @syncfusion/ej2-angular-calendars --save

Syncfusion Angular component suite is the only suite you will ever need to develop an Angular application faster.

Adding Angular 8 Calendar

  1. Refer to the Syncfusion CDN link of CSS reference within the html file.
     <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" / >
    
  2. Start to 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 ]
    })
    
    
  3. Define the Angular Calendar code within the app.component.html file mapped against the templateUrl option in the app.component.ts file.
    <ejs-calendar id=calendar [value]='value' [min]='minDate' [max]='maxDate' > </ejs-calendar >
  4. Here, the Calendar component is rendered with the min and max properties.
    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 () {}
    }
    
    
  5. Run the application with the command ng serve, and you’ll have a calendar with minimum and maximum dates, which will be displayed in the browser as shown in the following.

    Adding Essential JS 2 Calendar component in an Angular application
    Adding Essential JS 2 Calendar component in an Angular application

Multiple date selection

Calendar allows selecting a single date, multiple dates, or a sequence of dates using the isMultiSelection and values properties. By default, the isMultiSelection property is false. Use the following code to enable the multiple date selection feature.

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 () {}
}
<ejs-calendar id=calendar [values]='value' [isMultiSelection]='multiSelect'  > </ejs-calendar >
Selecting multiple days in Essential JS 2 Calendar
Selecting multiple days in Essential JS 2 Calendar

Find the right property to fit your requirement by exploring the complete documentation for Syncfusion’s Angular components.

Changing the first day of week

The Calendar component automatically updates the first day of the week based on the specified culture, and we can also change it based on the application requirements.

An option to change the first day of the week is using the firstDayOfWeek property. Days of the week go from 0 (Sunday) to 6 (Saturday). We are going to set Tuesday as the first day of the week.

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;
    public weekStart: number = 2;
    constructor () {}
}
<ejs-calendar id=calendar [values]='value' [isMultiSelection]='multiSelect' [firstDayOfWeek]='weekStart'   > </ejs-calendar >
Setting Tuesday as the first day of the week in Essential JS 2 Calendar
Setting Tuesday as the first day of the week in the Essential JS 2 Calendar

Islamic Calendar (Hijri calendar)

The Islamic calendar, or Hijri calendar, is a lunar calendar consisting of 12 months in a year of 354 or 355 days. To learn more about the Islamic calendar, please refer to Wikipedia.

By default, the calendar mode is Gregorian. You can enable the Islamic mode by setting the calendarMode to Islamic. We also need to import and inject the IslamicService module into the providers (app.module.ts).

import { CalendarModule, IslamicService } from '@syncfusion/ej2-angular-calendars';
@NgModule({ 
    imports: [ BrowserModule, CalendarModule ],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ],
   providers: [IslamicService]
})

Now, you can set the calendarMode property to Islamic in the calendar code (app.component.html).

<ejs-calendar id=calendar [values]='value' [isMultiSelection]='multiSelect' [firstDayOfWeek]='weekStart' calendarMode='Islamic'    > </ejs-calendar >
Configuring Essential JS 2 Calendar to Islamic calendar
Configuring Essential JS 2 Calendar to the Islamic calendar

See the possibilities for yourself with live demos of Syncfusion Angular components.

Conclusion

We hope you found this a useful overview of the Calendar component and its important features. Check out the other features of Calendar by downloading the free 30-day trial or cloning it from GitHub. Also, feel free to look at our online samples and documentation to explore other options.

If you wish to send us feedback or would like to ask any questions, please feel free to post in the comments section below or contact us through our support forum, support portal, or feedback portal.

Related blogs

Tags:

Share this post:

Comments (3)

need to change colour and width of calender
how can i do it
help me if you get my point

Want to know, how to customize the design of the calendar like color and size of boxes.

Hi HIMESH / HAMMAD,

Yes, we can modify the calendar width and color with help of using cssClass property and override the CSS styles as mentioned below,

[app.component.css]
.e-custom.e-calendar {
max-width: 300px;
background: #daa6b9;
}

[app.component.html]

[app.component.ts]
public cssClass = “e-custom”;

Sample Link: https://stackblitz.com/edit/angular-78wti5-ehj2ly?file=app.component.ts

Regards,
Saravanan G

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed