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?
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?
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
You need to pipe the date to follow the input format.