We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create an Angular 4 DateRangePicker component

Platform: Angular - EJ 2 |
Control: DateRangePicker

You can create an Angular 4 DateRangePicker component with minimal code configuration using this quick start project.


Angular 4 DateRangePicker


The following section explains the steps required to create a simple Angular 4 DateRangePicker component.




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



The Angular 4 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.




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


Creating Angular Project


You can see the Angular project creation steps using the Angular CLI tool.

Install the Angular CLI application in your machine.

npm install @angular/cli@1.4


Now, create a new Angular project using the ng new command 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 4 DateRangePicker


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

Import the DateRangePicker module into 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';
    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.




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 () {}




<ejs-daterangepicker placeholder='Select a range' [startdate]='start' [enddate]='end'></ejs-daterangepicker>


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




<link href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />


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




DateRangePicker displayed with start and end dates


Also, you can download and run the sample from this GitHub Repository. For more information about DateRangePicker functionalities, refer to UG Documentation, API Reference and Samples.

2X faster development

The ultimate Angular UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile