1

hi i am using angular material DatePicker https://material.angular.io/components/datepicker/examples, and i need to choose Year only, how do i do this properly? here is what i do :

<div class="form-group row">
    <label class="col-xl-3 col-lg-3 col-form-label">Production Year</label>
    <div class="col-lg-9 col-xl-8">
        <mat-form-field>
            <input matInput [matDatepicker]="productionYearPicker" placeholder="Choose a date"
                   formControlName="productionYear"
                   [class.is-invalid]="isControlInvalid('productionYear')"
                   [class.is-valid]="isControlValid('productionYear')">
            <mat-datepicker-toggle matSuffix [for]="productionYearPicker"></mat-datepicker-toggle>
            <mat-datepicker #productionYearPicker startView="multi-year"></mat-datepicker>
        </mat-form-field>
    </div>
</div>

the datePicker could start with year, but i still have to choose the month, and in the inputbox, when i type year only, it automatically format it to 1 january, how can i disable month and date? i only need year picker

Ke Vin
  • 3,478
  • 11
  • 60
  • 91
  • 1
    Seems excessive, but you could adapt their last example into [this](https://stackblitz.com/edit/angular-1qwgmb?file=src/app/datepicker-views-selection-example.ts) – Andrew Allen Jun 03 '21 at 10:52
  • 1
    I think it would be better UX to just use a select – robbieAreBest Jun 03 '21 at 20:34
  • Hi, check out this post https://stackoverflow.com/questions/60037470/how-to-select-only-year-on-mat-datepicker and https://stackblitz.com/edit/angular-mulitdate-picker-demo – Rok Ivartnik Jun 04 '21 at 06:19

0 Answers0