简体   繁体   中英

How to get value from Native Storage ZoneAwarePromise in Ionic 4

I am trying to get value from Native Storage with Service and Promise but i am getting value as ZoneAwarePromise

Inside Service:

  async getDataStorage(key:any): Promise<any>{
    return new Promise(resolve => {
      this.nativeStorage.getItem(key).then( res => resolve(res))
    });
  }

Inside class for accessing data from service function:

  newReq["sessionId"] = this.getSessionID();
  getSessionID(){
    var result = this.storageService.getDataStorage("sessionId");
    return result;
  }

Got Result:

{
sessionId: ZoneAwarePromise
__zone_symbol__state: true
__zone_symbol__value: {key: "20193251243251135926242866255036198243"}
__proto__: Object
}

Required Result:

{key: "20193251243251135926242866255036198243"}

Please try the following:

newReq["sessionId"] = this.getSessionID();
getSessionID(){
  this.storageService.getDataStorage("sessionId").then((result) => {
    return result;
  });  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM