How to use a variable outside the promise

Viewed 997

So i have a authorization token in my ionic storage and i have to pass it throught http request but i cant seem to get the value out of the storage.get.then promise.

  getProducts(){
    let headers = new Headers(); 
    this.token= this.storage.get('Authorization').then((value)=>{
       this.token= value;
      return this.token; 
     });
     headers.append("Authorization",this.token);

    return this.http.get('https://vjtest.cobold.xyz/vapi/public/api/products',{headers: headers})
      .map(res=> res.json());

  }
3 Answers
Related