My task is to put a today button on angular datepicker popup. (Selects the today date and closes popup)
<input matInput [matDatepicker]="toPicker" formControlName="validTo" >
<mat-datepicker-toggle matSuffix [for]="toPicker"></mat-datepicker-toggle>
<mat-datepicker #toPicker >
<mat-datepicker-actions>
<button mat-button (click)="goToday()">Today</button>
</mat-datepicker-actions>
</mat-datepicker>
The angular function:
@ViewChild('toPicker') toPicker: MatDatepicker<Date>;
goToday() {
this.toPicker.select(new Date());
this.toPicker.close();
}
This works! Unfortunately the default date selection is broken. I can click on a date but the popup remains open. Do you have idea how to add a today button and preserve the default funcionality
I have the same problem in my project and I have an idea. I hope it can help you.
You can call the insertButton() in the click event of mat-datepicker-toggle and date picker input. It still work for me