Search code examples
angularsqlitetypescriptionic3ionic-storage

Get Ionic storage item as a string


As said in the title my problem is when I do:

this.storage.get('user')

I get this object

t {__zone_symbol__state: null, __zone_symbol__value: Array(0)}

and I don't know how to manipulate it.

I'm asking if there is a way to get a string value from my storage example

// when i store user id like that 
this.storage.set("user", JSON.stringify(userID));
console.log(this.storage.get('user'))//output 100 for example


Solution

  • Ionic storage returns a promise of the data. So, you have to wait for the promise to get resolved and get the data like below:

    this.storage.get('user').then((result) => {
          console.log('My result', result);
    });