What is the use of Bootstrap Datepicker in Angular?
Last Updated :
28 Apr, 2025
In this article, we will see the use of Bootstrap Datepicker in Angular. The Datepicker is used to make a component that will be shown by using a calendar and we can select the date from it. Adding Bootstrap to the Angular Project can make the better UI design, along with providing some in-built classes for Date that help us to implement it directly.
Bootstrap Datepicker in Angular can be used in the following ways:
- Adding Bootstrap through Angular CLI & NPM, & then creating & using the Datepicker Component
- By installing the Angular ngx Bootstrap & then using the Datepicker Component (Angular ng Bootstrap Datepicker Component)
Steps for Installing & Configuring the Angular Application
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install dependency
ng add @ng-bootstrap/ng-bootstrap
npm install --save angular-bootstrap-datetimepicker bootstrap moment open-iconic
Step 4: Add CSS to ./src/styles.css
@import '~bootstrap/dist/css/bootstrap.min.css';
@import '~open-iconic/font/css/open-iconic-bootstrap.css';
Project Structure
It will look like the following:

Example 1: In this example, we will create a simple Bootstrap Datepicker in Angular. We will be adding Bootstrap through Angular CLI & NPM, & then creating & using the Datepicker Component.
HTML
<!-- app.component.html -->
<h2 style="color: green;">GeeksforGeeks</h2>
<h2>
What is the use of Bootstrap
Datepicker in Angular?
</h2>
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control"
placeholder="yyyy-mm-dd"
name="dp"
[(ngModel)]="model"
ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar"
(click)="d.toggle()"
type="button">
</button>
</div>
</div>
</div>
</form>
JavaScript
// app.component.ts
import { Component } from '@angular/core';
import { BrowserModule, DomSanitizer } from
'@angular/platform-browser'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
model: any
}
JavaScript
//app.module.ts
import { NgModule }
from '@angular/core';
import { FormsModule, ReactiveFormsModule }
from '@angular/forms';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent }
from './app.component';
import { NgbModule }
from '@ng-bootstrap/ng-bootstrap';
import { DlDateTimeDateModule, DlDateTimePickerModule }
from 'angular-bootstrap-datetimepicker';
@NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
ReactiveFormsModule,
DlDateTimeDateModule,
DlDateTimePickerModule,
]
})
export class AppModule { }
Output:

Example 2: In this example, we will use Bootstrap Datepicker in Angular by ngx Bootstrap & then use the Datepicker Component (Angular ng Bootstrap Datepicker Component). We will also display the selected date in the text.
HTML
<!-- app.component.html -->
<h2 style="color: green;">GeeksforGeeks</h2>
<h2>
What is the use of Bootstrap
Datepicker in Angular?
</h2>
<ngb-datepicker #dp [(ngModel)]="model"
(navigate)="date = $event.next">
</ngb-datepicker>
<hr />
<pre>Selected Date: {{ model | json }}</pre>
JavaScript
//app.component.ts
import { Component, inject }
from '@angular/core';
import { NgbCalendar, NgbDatepickerModule, NgbDateStruct }
from '@ng-bootstrap/ng-bootstrap';
import { FormsModule } from '@angular/forms';
import { JsonPipe } from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
imports: [NgbDatepickerModule, FormsModule, JsonPipe],
standalone: true,
})
export class AppComponent {
model: NgbDateStruct;
date: { year: number; month: number };
}
JavaScript
//app.module.ts
import { NgModule }
from '@angular/core';
import { FormsModule, ReactiveFormsModule }
from '@angular/forms';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent }
from './app.component';
import { NgbModule }
from '@ng-bootstrap/ng-bootstrap';
@NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
ReactiveFormsModule,
NgbModule
]
})
export class AppModule { }
Output:

Similar Reads
How to make Datepicker using Angular UI Bootstrap ? In this article, we will see how to make Datepicker using Angular UI bootstrap. Angular UI Bootstrap is an Angular JS framework created by Angular UI developers for providing better UI which can be used easily. Syntax: <div uib-datepicker></div> Download AngularUI from the link: https://
1 min read
How to make Timepicker using Angular UI Bootstrap ? In this article, we will see how to make Dropdown using Angular UI bootstrap. Angular UI Bootstrap is an Angular JS framework created by Angular UI developers to provide better UI which can be used easily. Syntax: <div uib-timepicker></div> Download AngularUI from the link: https://angul
1 min read
Angular ng Bootstrap Datepicker Component Angular ng bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites. In this article, we will see how to use Datepicker in angular ng bootstrap. The Datepicker is used to make a compone
1 min read
How to setting up Datepicker in Bootstrap ? A Datepicker is an input tool that allows users to select dates from a calendar view rather than typing manually. To set it up in Bootstrap, integrate the Bootstrap Datepicker library using HTML, CSS, jQuery, and Bootstrap, customizing it with various options for functionality.Datepicker In FormsSyn
3 min read
How to use bootstrap 4 in angular 2? Bootstrap is an open-source toolkit for developing with HTML, CSS, and JS. The Bootstrap framework can be used together with modern JavaScript web & mobile frameworks like Angular. Bootstrap 4 is the newest version of Bootstrap, which is the most popular HTML, CSS, and JavaScript framework. This
2 min read