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

How to solve the Promise returned by the Ionic storage?

$
0
0

@ioclaudio wrote:

Hi,
I’m trying to read a token from the Ionic storage with a “get”.
I know it returns a Promise but I’ve defined this asynchronous method:

  async getToken() {
    return await this.storage.get('TOKEN_KEY');
  }

  getWsHeader() {
    let tempToken;
    tempToken = this.getToken();
    console.log('@@@@@@@ TOKEN:', tempToken);

When I run this code the variable “tempToken” is not a string but it is still a Promise.
How is it possible?
This is what I see in the Chrome console about “tempToken”:
ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array(0)}

I’m using this version of Ionic:

Ionic:
   ionic (Ionic CLI)             : 4.12.0
   Ionic Framework               : @ionic/angular 4.1.2
   @angular-devkit/build-angular : 0.13.6
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.6
   @ionic/angular-toolkit        : 1.4.1
System:
   NodeJS : v10.15.1
   npm    : 6.7.0
   OS     : Windows 10

Thank you very much

cld

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70442

Trending Articles



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