Storage value showing undefined

Storage value showing undefined
this way to set value into the local storage

this.storage.set('username', this.user_name);
          this.storage.set('user_id', this.user_id);

Get this way

 constructor(){
 this.storage.get('username').then((val) => {
     this.name =val;
  });

where i’m wrong?
please help me anyone

}

1 Like

Hi
you must use “val” like an object:

 this.storage.get('username').then((val) => {
     this.name =val.username;
  });

this.storage.get('user_id').then((val) => {
     this.name =val.user_id;
  });

its still showing same error

please paste here this error

When i try to print the from of this.name showing undefined

TypeError : showing val is null

I guess you run the application in a browser. Storage is native functionality so it works only on the device. All native plugin works only on the device.

I’m following https://ionicframework.com/docs/storage/ this tutorial

Nope. can and will work in browser.

You need to test for null value, meaning the value is not stored. If that is not what you expect, then there is something else going on. Including the storage being cleared after you close the browser and/or reload the app. Then you need to set the storage engine according to the docs, where still data can be cleared due to the nature of the browser

1 Like

you right

@flycoders_sourav
I implemented in my application ‘storage’ and all work fine. In browser developers tools check what value is ‘this.user_name’. Maybe you set a value of ‘null’