【发布时间】:2023-03-29 06:52:01
【问题描述】:
在我的全栈项目中,我需要在公式中更新日期,为此,我使用公式从数据库中接收数据,并使用数据库中的原始值设置输入。问题是当我尝试设置 mdDatepicker 的输入时,我不知道我做错了什么。这是错误
错误:Datepicker:值未被 DateAdapter 识别为日期对象。
后端:nodejs 数据库:mysql 前:角4
类
export class Empresa {
constructor(
public NUM_ID_EMPRESA: number,
public STR_IDENTIFICACION: number,
public STR_TIPO_IDENTIFICACION: number,
public STR_NOMBRE: string,
public createdAt: string
) {}
}
这是用于编辑公式的控件
createControlsEdit() {
this.form = this.fb.group({
NUM_ID_EMPRESA: '',
STR_NOMBRE: ['', Validators.compose([Validators.required])],
STR_TIPO_IDENTIFICACION: ['', Validators.compose([Validators.required])],
STR_IDENTIFICACION: ['', Validators.compose([Validators.required, Validators.pattern(validaNum)])],
createdAt: '' // this is the control for date
})
}
这是我的配方补丁值
this.service.getEmpresa(id)
.subscribe(
rs => this.empresa = rs,
er => console.log('Error:', er),
() => {
if (this.empresa.length > 0) {
this.esEdicion = true;
this.form.patchValue({
NUM_ID_EMPRESA: this.empresa[0].NUM_ID_EMPRESA,
STR_NOMBRE: this.empresa[0].STR_NOMBRE,
STR_TIPO_IDENTIFICACION: this.empresa[0].STR_TIPO_IDENTIFICACION,
STR_IDENTIFICACION: this.empresa[0].STR_IDENTIFICACION,
createdAt: this.empresa[0].createdAt // here recieve data from model
})
}
}
)
}
这是我的 mdDatePicker html 视图
<div class="form-group">
<md-form-field>
<input id="createdAt" formControlName="createdAt" mdInput [mdDatepicker]="picker" (click)="picker.open()" placeholder="Elija una fecha">
<md-datepicker-toggle mdPrefix [for]="picker" ></md-datepicker-toggle>
<md-datepicker #picker></md-datepicker>
</md-form-field>
</div>
谢谢
【问题讨论】: