Setting input type date min value to current date angular 12

Viewed 1289

I have an input date-picker and I want to set its min value to the current date

<input type="date" class="form-control" id="checkindate" placeholder="" min="">

how can I do this using Angular?

2 Answers

You need to pipe the date to follow the input format.

Here Demo

There are multiple ways to do it. The min attribute accepts a string in multiple formats. Here is my solution using 'yyyy-mm-dd'.

Controller (*.ts)

export class AppComponent {
  currentDate: string;

  constructor() {
    // credit: https://stackoverflow.com/a/38148759/6513921
    this.currentDate = new Date().toISOString().slice(0, 10);
  }
}

Template (*.html)

<input type="date" class="form-control" id="checkindate" placeholder="" [min]="currentDate">

Working example: Stackblitz

Related