#Not able to display data in local storage to form

18 messages · Page 1 of 1 (latest)

sage umbra
#

window.localStorage ?

stable steeple
#

No that doesnt work

jade vector
#

are you sure that this data exists in local storage?

stable steeple
#

@jade vector yeah the data is getting transferred to local storage

#

but im not able to retrieve it and prepopulate the form

hallow fox
#

In your screenshot, key is called step, not STEP_1

stable steeple
#

i changed that, still not working

#

@hallow fox

hallow fox
#

Show a screen of your current localstorage and the code for createRegForm

stable steeple
#

@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],
    });
  }
hallow fox
#

Add this log here

console.log(draft);
if (draft) {
      this.formData.setValue(JSON.parse(draft));
    }

And post what gets logged in console.

stable steeple
#

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));
    }
hallow fox
#

Try to replicate your issue in Stackblitz.