Hi
I have below data in Local Storage and i want to save data is studentObj. I am using Rective form
studentObj: Student = new Student();
studentList:Student[] = [];
get f(){
return this.form.controls;
}
Thanks
Hi
I have below data in Local Storage and i want to save data is studentObj. I am using Rective form
studentObj: Student = new Student();
studentList:Student[] = [];
get f(){
return this.form.controls;
}
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted May 15, 2024, 6:44 AM
If you want to save data in
studentObjand you are using Reactive Forms, you can do something like this:In the above code,
ngOnInitis used to initialize the form withFormControlfor each field. ThesaveDatamethod is used to save the form data tostudentObjand then pushstudentObjtostudentList.Remember to call
saveDatamethod when you want to save the data, for example, on a button click.Please replace
'name','age'and other properties with your actual Student class properties. Also, don’t forget to importFormGroupandFormControlfrom@angular/forms.thanks
Vishal JoshiPosted May 15, 2024, 6:15 AM
Hello Ramco
You can use the localStorage to store the data in local storage.
please check-out the below code.
To set the value:
JSON.stringify() is needed if you are storing an object.
To get the stored object from localStorage:
Thanks
Vishal Joshi
Jignesh KumarPosted May 15, 2024, 5:04 AM
Hello Ramco,