0
基本上是以这种形式。我有onsubmit函数,这将在LocalStorage中保存从日期和toDate。在component.ts中,我试图定义一个函数,它将从本地存储中提取日期数据并设置表单值。而且似乎设置表单值不适合我。下面是代码:如何从LocalStorage中设置angular2形式的值
在component.ts
@ViewChild ('formRef') form;
this.form.fromDate = new Date(localStorage.getItem("startDate")).getDate() ;
this.form.toDate = new Date(localStorage.getItem("endDate")).getDate() ;
component.html
<input name="fromDate" id="fromDate" type="date" [(ngModel)]="fromDate"
#fromDate ="ngModel"
required>
<input name="toDate " id="toDate " type="date" [(ngModel)]="toDate "
#toDate ="ngModel"
required>
我验证了LocalStorage具有正确的值。这里的问题是我如何更新表单值,在浏览器控制台中,this.fromDate = localStorage.getItem(“endDate”)的作品。但在我的TS代码中,它不起作用。 – NewJake