Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To avoid taking future date in material datepicker component

I am using material datepicker component, I want restrict the future dates in datepicker component, While surfing i found the solution solution1 ,solution2, but these solution suits good for normal datepicker.But i want to restrict in material datepicker.If possible please provide the solution in this DEMO.

like image 841
Shankar Avatar asked Mar 15 '19 05:03

Shankar


1 Answers

MatDatepickerInput has an @Input for this

@Input()
max: D | null

See this short example:

<mat-form-field>
  <input matInput [matDatepicker]="picker" [max]="today" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

TS file:

today = new Date(); 
like image 118
Carsten Avatar answered Nov 26 '22 07:11

Carsten