首页 > 解决方案 > 如何使角度材料日期选择器仅选择年份?

问题描述

嗨,我正在使用角度材料 DatePicker https://material.angular.io/components/datepicker/examples,我只需要选择年份,我该如何正确执行此操作?这就是我所做的:

<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>

datePicker 可以从年份开始,但我仍然必须选择月份,并且在输入框中,当我只输入年份时,它会自动将其格式化为 1 月 1 日,我怎样才能禁用月份和日期?我只需要年份选择器

标签: angularangular-materialmaterial-ui

解决方案


推荐阅读