如何使角材料日期选择器仅选择年份?

时间:2021-06-03 10:20:48

标签: angular angular-material material-ui

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

<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 日,我如何禁用月份和日期?我只需要年份选择器

0 个答案:

没有答案