Dexter
Dexter

Reputation: 113

How to get property value from ionic 2 storage

I have a Promise which i used to get the stored data of in an Ionic storage

return new Promise(resolve => resolve(this._storage
.get("user")
.then(value => value)));

and it prints out {"user-profile":"user","acct_no":"1234567890"}

how do i get the property value of acct_no? which will be 1234567890

Upvotes: 0

Views: 895

Answers (2)

Saravana
Saravana

Reputation: 40692

Your return new Promise ... does not make much sense as storage.get already returns a promise. You could just do return this._storage .get("user"); which would have the same effect. To get the acct_no property, just access it in the callback:

this._storage
    .get("user")
    .then(value => {
        console.log(value.acct_no);
    });

Upvotes: 1

Emeka Obianom
Emeka Obianom

Reputation: 1794

Just correct your code to this...

return new Promise(resolve => resolve(this._storage
.get("user")
.then(value => value.acct_no)));

Upvotes: 2

Related Questions