runtimeZero
runtimeZero

Reputation: 28086

why does ionic2 storage fail to retrieve value?

I am using ionic2 storage a below:

//page2.ts
import { Storage } from '@ionic/storage';

export class LoginPage {
   ...

  //this works fine
  onLogin(){
    this.storage.set('uid', '12345');
  }

}

//page2.ts

export class Foo {

   //no value gets retrieved here
  onSave() {
    this.storage.get('uid')
    .then(uid =>  console.log(uid));
  }
}

No value gets retrieved and no error is thrown, what am i missing ?

Upvotes: 0

Views: 132

Answers (1)

ACES
ACES

Reputation: 490

Try using NativeStorage. It is one of native-ionic plugins and it won't be deleted unless you programmatically delete it or user deletes an app. With NativeStorage you would do.

NativeStorage.setItem('uid',{value: this.uid}.then(()=>{
console.log("uid is saved);
})

NativeStorage.getItem('uid').then((data)=>{
console.log("uid value is: " + data.value);
})

Upvotes: 1

Related Questions