admin管理员组文章数量:1310475
I want to store reactive forms data to local storage and access that data to another page.
<form [formGroup]="testform" >
firstname:
<input type="text" formControlName="fname"><br>
lastname:
<input type="text" formControlName="lname">
<button type="submit" (click)="Submit(testform)">Submit</button>
</form>
I hope anyone knows the issue. Thank you.
I want to store reactive forms data to local storage and access that data to another page.
<form [formGroup]="testform" >
firstname:
<input type="text" formControlName="fname"><br>
lastname:
<input type="text" formControlName="lname">
<button type="submit" (click)="Submit(testform)">Submit</button>
</form>
I hope anyone knows the issue. Thank you.
Share Improve this question edited Nov 19, 2019 at 5:41 Prashant Pimpale 10.7k10 gold badges50 silver badges87 bronze badges asked Jun 24, 2019 at 7:03 user11675217user11675217 6- Do you face any issue to do that? – Prashant Pimpale Commented Jun 24, 2019 at 7:11
- i dont know how to do that – user11675217 Commented Jun 24, 2019 at 7:13
- Check the posted answer – Prashant Pimpale Commented Jun 24, 2019 at 7:15
- You should store the data in a service instead of local storage – Augustin R Commented Jun 24, 2019 at 7:17
- will u explain how to do that? – user11675217 Commented Jun 24, 2019 at 7:54
1 Answer
Reset to default 7To set the value:
JSON.stringify() is needed if you are storing an object.
localStorage.setItem('form-data', JSON.stringify(this.testform.value));
and to get the stored object from localStorage:
let formValue = JSON.parse(localStorage.getItem('form-data'))
本文标签: javascriptHow to store reactive form data to localstorageStack Overflow
版权声明:本文标题:javascript - How to store reactive form data to localstorage? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741761884a2396456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论