Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70746

Ionic 3 storage read/write issues

$
0
0

@aliaslam7163 wrote:

So I am using ionic storage to read something out of the storage and if the value to the key is empty i want to then set that value, and make another check(get) to see if the value was set. However, I am having a difficult time understanding promises so I considered wrapping the promise with an observable. However The issue that I am still running into is the data that is being returned is very confusing. The data is an object and before execution the object has two keys {__zone_symbol__state:true, __zone_symbol__value:array{0}} and after i guess the promise is finished i get {__zone_symbol__state:true, __zone_symbol__value:‘Current datetime’} which is exactly what im hoping for. However, due to the inability to understand the object or even how the promise is working, my if/else statement to capture the '__zone_symbol__value:…" are inadequete because Im using the if/else to determine which rootpage to go to.

below is the code in my provider/service:
getLoginStatus(){

let myObservable = Observable.create(observer => {
  console.log('observer is setup');

  observer.fromPromise(this.storage.get('loginStatus'));
});

myObservable.subscribe((data) => {
this.getData = data;
console.log(this.getData);
});
return this.getData;

}

below is the code in my app.component.ts:

platform.ready().then(() => {

  //this.StartupProvider;
  this.getData = this.LoginStatusProvider.getLoginStatus();
  console.log(this.getData.__zone_symbol__value);
  if(this.getData.__zone_symbol__value[0] == '')
  {
     this.LoginStatusProvider.setLoginStatus();
     this.rootPage = RetrieveDataPage;
  }
  else if (this.getData.__zone_symbol__value[0] != ''){
    console.log('Skipped the if');
    this.rootPage = LoginPage;

  }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70746

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>