Angular Material Datepicker Disable Previous Dates Example

By Hardik Savani | December 22, 2020 | Category : Angular

Hello Dev,

Now, let's see post of angular material datepicker disable previous dates. let’s discuss about angular material datepicker disable past dates. you'll learn how to disable previous date in datepicker using angular. Here you will learn how to disable past date in datepicker using angular.

we can easily disable previous date material datepicker in angular 6, angular 7, angular 8, angular 9, angular 10 and angular 11 app.

In this example, we will add material design theme and then import some dependency module of datepicker. then we will simply write code of datepicker from angular document. angular material datepicker provide min and max attribute where you can set dates that you want to disabled it.

So, let's see bellow example from here:

Step 1: Create New App

You can easily create your angular app using bellow command:

ng new myDatepicker

Step 2: Add Material Design

Now in this step, we need to just install material design theme in our angular application. so let's add as like bellow:

ng add @angular/material

Cmd like bellow:

Installing packages for tooling via npm.

Installed packages for tooling via npm.

? Choose a prebuilt theme name, or "custom" for a custom theme: Indigo/Pink

[ Preview: ]

? Set up HammerJS for gesture recognition? Yes

? Set up browser animations for Angular Material? Yes

Step 3: Import Module

In third step, we need to import some dependency like MatDatepickerModule, MatNativeDateModule, MatInputModule. so let's add.


import { NgModule } from '@angular/core';

import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatDatepickerModule } from '@angular/material/datepicker';

import { MatNativeDateModule } from '@angular/material/core';

import { MatFormFieldModule } from '@angular/material/form-field';

import { MatInputModule } from '@angular/material/input';


declarations: [



imports: [








providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 4: Updated ts file

Now in ts file, add bellow code:


import { Component } from '@angular/core';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent {

title = 'my-app';

minDate = new Date();


Step 5: Update html file

Now in view file, we will write code of input element with datepicker as like bellow:


<h1>how to disable previous date in datepicker using angular - ItSolutionStuff.Com</h1>


<input matInput [matDatepicker]="picker" [min]="minDate" placeholder="Choose a date">

<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>

<mat-datepicker #picker ></mat-datepicker>


Now we are ready to run our example, you can run by following command:

ng serve

you will see layout as bellow:

I hope it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: