首页 > 解决方案 > 将日期绑定到 Angular7 中的 formControlname 输入

问题描述

我是角度的新手。我有一个 type 的输入date。如何将日期绑定到此输入?

<input type="date" class="form-control" formControlName="startDateInput">

我尝试了以下但没有奏效:

this.createForm.patchValue({
    startDateInput:this.resourceData['period'].start,
});

请帮忙

标签: angularangular7

解决方案


对于日期类型输入,您需要转换日期

this.createForm.patchValue({ 
    startDateInput: (new Date()).toISOString().substring(0,10), 
});

演示


推荐阅读