#Not able to display data in local storage to form
18 messages · Page 1 of 1 (latest)
No that doesnt work
are you sure that this data exists in local storage?
@jade vector yeah the data is getting transferred to local storage
but im not able to retrieve it and prepopulate the form
In your screenshot, key is called step, not STEP_1
Show a screen of your current localstorage and the code for createRegForm
@hallow fox
createRegForm() {
this.formData = this.fb.group({
id: [null, [Validators.required, Validators.maxLength(6)]],
name: [null, Validators.required],
email: [null, [Validators.required, Validators.email]],
gender: [null, Validators.required],
});
}
Add this log here
console.log(draft);
if (draft) {
this.formData.setValue(JSON.parse(draft));
}
And post what gets logged in console.
here is the log - {"id":123,"name":"sad","email":"sda@g","gender":"sad"}
@hallow fox
let draft = window.localStorage.getItem('step');
console.log(draft);
if (draft) {
console.log(this.formData);
this.formData.setValue(JSON.parse(draft));
}
this is the log i get
Try to replicate your issue in Stackblitz.