在.ts文件中
this.form = this.fb.group({
.....
ReceiptDateTime:['',],
)}
在.html文件中
<tr>
<td width="50%"><label for ="ReceiptDateTime">Transaction date: </label></td>
<td width="50%"><label> <input type="date" formControlName="ReceiptDateTime" value ="receipt.ReceiptDateTime">
</label></td>
</tr>
当我们运行时发生的是它是被动形式默认打印日期文本为dd --- yyyy它不接受列表中的值.ReceiptDateTime包含日期但不起作用。
答案 0 :(得分:0)
在Html部分:
<input type="date" formControlName="ReceiptDateTime" #myDate [value]="receipt.ReceiptDateTime| date:'yyyy-MM-dd'" (input)="receipt.CreatedDate=parseDate($event.target.value)" />
在ts部分声明解析函数:
parseDate(dateString: string): Date {
if (dateString) {
return new Date(dateString);
} else {
return null;
}