Not able to display data in local storage to form
I was creating a way to save form data even when navigating to another component. The data gets saved to local storage but I'm not able to pre-fill the form using the data stored in local storage. It was working yesterday but today it is'nt working. Can anyone show me what I'm doing wrong. Here is the code for it.
17 Replies
Are you getting errors in the console. Try to log the values draft and val. Can you see the data in Developer Tools > Storage > Local Storage?
@markboots. Yeah i can see the values in local storage
okay, here you going wrong
this.formData.setValue(JSON.parse(draft));
I do not know what library you are using, but i think you are missing the formData field name. I think setValue needs the name
of the input & the value
yeah I did that but still not working @markboots.
Ah ok, it not just 1 value, it is the complete form. Im not familiar with Angular, but I'll do some searching
yeah the complete form data should be repopulated
in regular JS it would be formData.set("name", value) for each field. so looping over the object.
I read the docs, it should indeed work like that. FormData.setValue indeed takes an object (had to confirm it formyself).
Is your codesnippet above still the same? because i see you call it
STEP_1
while in the storage screenshot it is step
. Can you update it
Also the error says this.formData.value
, not setValue
I tried to add window before local storage
@markboots.
window should not be necessary.
can you console.log
this.formData
in the if statement, before you set itHere is the object which the console is returning @markboots.
can you open the Prototypes? So we can see all the methods
Here it is @markboots.
hm, so we are missing the setValue method. Im out of ideas now. If you have some time, we better wait for someone with Angular experience. Maybe we are missing something obvious
Okay
@jochemm do you have any idea why I cant retrive the data?
nope, sorry, never really used Angular
Oh okay