0
votes

I’m working on a http request. I've faced problem previously which my object shows [object promise] in the URL request. So i had await the return of the Promise of the object which is my user variable.

But I'm now getting an error

Property 'subscribe' does not exist on type Promise<Observable<any>>.

I also googled this and have done necessary changes but the outcome is the same.

this is my code of the http request:

async getUserFromStorage():Promise<any>{
    return await this.storage.get('currentUser');
}

async getUserOrder()
{
  const user = await this.getUserFromStorage();
  var url="https://localhost:44399/api/APIOrder/GetUserOrder?email=";
  console.log(url+user);
  return this.http.get(url+user).map(res=>res.json());
}

This is the code which is failing:

    public getOrders(){
    this.getUserOrder()
    .subscribe(data =>{                //HERE
      for(var i=0;i<data.length;i++)
      {
        this.orders.push(data[i]);
      }
    })
    return this.orders;
}
2

2 Answers

2
votes

try:

const getUserOrder = await this.getUserOrder();
getUserOrder.subscribe(data => {
...

The reason is that you are missing await


Like @Brendan B mention there's also no reason for the async on getUserOrder method actually, sense you are returning an Observable. You can also delete the async keyword from this method and it'll work.

1
votes

async functions don't return promises, you are trying to subscribe to a promise.

Try removing the async from async getUserOrder()