Search code examples
angular-materialangular8mat-datepicker

How to select only year on mat-datepicker


I'm developing an application with angular 8 in which I have an input that contains only year number. I have used mat-datepicker and want only to choose year.

<mat-form-field class="input-control">
      <input matInput placeholder="{{'enter'|translate}}.." [formControl]="form.controls.openedAt"
             [matDatepicker]="date" readonly>
      <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
      <mat-datepicker #date startView="multi-year"></mat-datepicker>
    </mat-form-field>

this code shows year view first, but when I choose the year, the month view will be opened, then days view.

So how can I select only year, or show only year view on mat-datepicker?


Solution

  • This feature is not fully implemented yet. You can see that here:

    https://github.com/angular/components/issues/4853

    For now you can try this:

    https://stackblitz.com/edit/angular-mulitdate-picker-demo