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'))