我正在研究 Mat 日期选择器自定义值。这是我正在尝试的代码
<div class="form-group" *ngIf="selectVal.value == 'Date'">
<mat-form-field>
<input matInput [matDatepicker]="picker" (dateChange)="formatDate(dateValue.value)" #dateValue formControlName="assumptionValueInDatetime" class="form-control" placeholder="Choose a date" >
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
这是我的 ts 代码。这是我想要的格式 07-JUL-2020
formatDate(value) {
const months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
let formatDate = ('0' + value.getDate()).slice(-2) + "-" + months[value.getMonth()] + "-" + (value.getFullYear());
return formatDate;
}
这是我的有效载荷的样子:
initassumpationForm() {
this.assumptionDesignForm = this.fb.group({
assumptionValueInDatetime: this.formatDate(this.assumptionValueInDatetime)
});
}
得到错误为:
错误类型错误:无法读取未定义的属性“getDate”