Articles in this section
Category / Section

How to create an example of angular daterangepicker component using bootstrap theme?

This article explains how to create an example of angular daterangepicker component using bootstrap theme.

Angular DateRangePicker

The following section explains the steps required to create a simple Angular DateRangePicker component in the Bootstrap theme.

Pre-requisites

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


Introduction

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


Dependencies

Before starting this project, the Angular DateRangePicker requires to adding Syncfusion ej2-angular-calendars package from the npmjs, which is distributed in npm as @syncfusion scoped packages.


Creating Angular Project

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

Install Angular CLI using the following command.

npm install -g @angular/cli
  

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 using the npm install command.

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

Adding Angular DateRangePicker


You can add the Angular DateRangePicker component by using the ejs-daterangepicker directive and the attributes within the tag, which allows you to define other functionalities.

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

 

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

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

Here, the DateRangePicker component is rendered using the startDate and endDate properties.

[app.component.ts]

import {Component} from '@angular/core';
 
@Component ({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
 
export class AppComponent {
    public start: Date = new Date ("10/07/2017"); 
    public end: Date = new Date ("11/25/2017");
    constructor () {}
}

 

[app.component.html]

<ejs-daterangepicker id='daterangepicker' placeholder='Select a range' [startDate]='start' [endDate]='end'></ejs-daterangepicker> 

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

[index.html]

<link href="//cdn.syncfusion.com/ej2/bootstrap.css" rel="stylesheet" />
 

 

Run the application with the ng serve command, then the DateRangePicker will be displayed with the start and end dates on the browser as shown below.

Screenshot

DateRangePicker


For more information about the DateRangePicker functionalities, refer to this UG Documentation, API Reference, and Samples.


Conclusion


We hope you enjoyed learning about how to create an example of angular daterangepicker component using bootstrap theme.

You can refer to our Angular feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our Angular daterangepicker example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsBoldDesk Support, or feedback portal. We are always happy to assist you!

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