I need to use JSON to store the form data, but I'm not sure how to go about it. I know I need to store all of the data that is gathered from text fields and radio buttons and then I need to make a form that displays the data. Can anyone point me to good resources for this? Or know how I can do this? I also need to know how I can access the data for another page since this is an application with two pages. One is for gathering data and the other is for displaying.
1 Answer
So basically to store form datas to JSON is simply create a JSON object and assign the form value to specified property inside that object.
my method is simple like this, on submit i add new object
let newValue = {
inputValue : this.form.value.input,
selectValue : this.form.value.select,
}
thats just for an example, assignin form value to the property of our new object. then to push the data to api simply like this
pushToAPIFunc(newValue);
and the result will be like this
{
"newValue" :{
"inputValue" : "inputValue",
"selectValue" : "selectValue"
}
}
to display that data, for example u have an edit page, u can use patchValue() of that JSON to your form, or assigning that data manually to each formControlName
1 Comment
Marco Antonio Martinez
Okay yeah that helps a lot. Thank you.
postSurvey()atcreate-survey.component.tsJSON.stringify(data). Does it store it in a JSON file?