Angular 材料日期选择器的修补程序值未设置日期
我有一个Firestore时间戳,我想分配给一个物料日期选择器,但我得到了一个日期格式错误 我已经使用datepipe将firestore时间戳转换为“yyyy-MM-dd”,如下错误所示 指定值“3/2/1981”不符合所需格式“yyyy-MM-dd” 引发此问题的代码是:Angular 材料日期选择器的修补程序值未设置日期,angular,datepicker,angular-material,Angular,Datepicker,Angular Material,我有一个Firestore时间戳,我想分配给一个物料日期选择器,但我得到了一个日期格式错误 我已经使用datepipe将firestore时间戳转换为“yyyy-MM-dd”,如下错误所示 指定值“3/2/1981”不符合所需格式“yyyy-MM-dd” 引发此问题的代码是: const bDate = this.datepipe.transform(this.user.birthday.toDate(), 'yyyy-MM-dd'); console.log(bDate);
const bDate = this.datepipe.transform(this.user.birthday.toDate(), 'yyyy-MM-dd');
console.log(bDate);
this.form.patchValue( {
birthday: bDate,
firstName: this.user.firstName,
lastName: this.user.lastName
});
我在控制台上记录bDate:
有趣的是,控制台日志显示“1981-03-03”,这正是错误所要求的格式。还请注意,这与错误“3/2/1981”相冲突
我还将包括datepicker模板,以便更好地度量:
<mat-form-field>
<input
matInput
placeholder="Your birthdate"
[matDatepicker]="birthdayPicker"
required
type="date"
formControlName="birthday"
name="birthday"
>
<mat-datepicker-toggle matSuffix [for]="birthdayPicker"></mat-datepicker-toggle>
<mat-datepicker #birthdayPicker></mat-datepicker>
</mat-form-field>
我不知所措。谢谢你的帮助