我是角度的新手。我有一个类型为 date
的输入。如何将日期绑定到此输入?
<input type="date" class="form-control" formControlName="startDateInput">
我尝试了以下方法,但没有奏效:
this.createForm.patchValue({
startDateInput:this.resourceData['period'].start,
});
请帮助做到这一点
对于日期类型输入,您需要转换日期
this.createForm.patchValue({
startDateInput: (new Date()).toISOString().substring(0,10),
});
演示
你可以
执行以下操作
const date = new Date();
this.createForm.controls['startDateInput'].setValue(date)