Starting from the selection of a date of birth, booking an event, scheduling an appointment, or entering a data field, date and time fields are a common part of modern Web and mobile applications. Not only does the datetime data entry need to be simple and easy to understand but also should look modern and responsive.
Infragistics’s Ignite UI provides a modern datepicker control that is not only modern and responsive but also provides simple and easy navigation and selection. The control is also responsive to any device of any size.
In this article, we will learn how to create a web app that demonstrates the use of Ignite UI datepicker control.
This article covers the following topics,
- Install Ignite UI for Angular
- Create an Angular Project with Ignite UI
- Import IgxDatePickerModule
- Add igx-datepicker
- Set default date in datepicker
- Adding cancel and today button
- Custom formatting
- Internationalization
- Conclusion
Introduction
The Ignite UI for Angular datepicker component displays a month-view calendar or a pop-up calendar that lets users pick a single date. It supports locales and custom date formatting. The component can also display today's calendar format.
If you already have Ignite UI installed, you can skip this step.
Step 1 - Install Ignite UI for Angular
You should have node and npm installed on your machine. If you are new to npm, check out the npm documentation here.
Open the command prompt and run
“npm install -g igniteui-cli”
Create an Angular project with Ignite UI
To create a new project run the below command:
“ng new igniteui-date-picker-demo”
To get into the project:
“cdigniteui-date-picker-demo”
Now, it’s time to install the Ignite UI for this project. Run the following command:
“npm install igniteui-angular”
Let’s add the required Ignite UI styles and the “HammerJs” library in the angular-cli.json.
Open the “angular.json” and add below code snippet as shown Listing 1.
- "styles": [
- "../node_modules/igniteui-angular/styles/igniteui-angular.css"
- ]
- "scripts": ["../node_modules/hammerjs/hammer.min.js"]
Listing 1.
Now, we have configured Ignite UI with our Angular project successfully.
Adding Material Icons
- /* style.css */
- @import url('https://fonts.googleapis.com/icon?family=Material+Icons');
Run the following command on command prompt to run the Angular application.
ng serve --open
The application will run using the following address and port “http://localhost:4200”
Step 2 - Import the IgxDatePickerModule
Open the “app.module.ts” file and import the IgxDatePickerModule in the import section of @NgModule
- import {
- IgxDatePickerModule
- } from 'igniteui-angular';
- @NgModule({
- imports: [
- IgxDatePickerModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule {}
Listing 2.
Step 3 - Add a page
Let’s add the new component named date-picker-page to do that run the below command on command prompt.
ng generate component components/date-picker-page
Listing 3.
Figure 1.
Now, add the <app-date-picker-page></app-date-picker-page> in app.component.html file.
Step 4 - Add a DatePicker control
Let’s add an igx-datePicker directive in “date-picker-page.component.html” page as shown in listing 4. This is the datepicker control that allows users to pick a date.
- <igx-datePicker></igx-datePicker>
Listing 4.
Now run your application using “ng server --open”.
The result will look like the following where you will see a datepicker control is launched with today’s date selected in the current month. Here, you can select any date from the month.
Figure 2.
Set default date in DatePicker
Let’s add the default value of DatePicker control.
Open the “date-picker-page.component.ts” and add the following line as shown highlighted in Listing 6. What this does is, sets the date of the calendar to today’s date.

MM JAckPosted Jul 17, 2024, 9:55 AM
Nyce Article
Jack SlatteryPosted Jan 23, 2020, 7:35 AM
Some of the " igx-datePicker " HTML lines need to be fixed to " igx-date-picker"