Angular material today button

Discussão em 'Angular' iniciado por Géza, Março 9, 2025.

  1. Géza

    Géza Guest

    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

    Continue reading...

Compartilhe esta Página