0

I'm trying to make an api call and assign the result using async code. here is what i have.

public async getInfoFeed(): Promise<Feed> {
    let returnVal: Feed;
    await this.http.get(url)
        .map(res => res.json())
        .subscribe( 
            data => returnVal = data, 
            err => console.log(err)
        )

        return returnVal;
}

var info = await this.getInfoFeed();
console.log(info);

by the time the code completes, info is 'undefined'. How can i make this method asynchronous?

patch321
  • 21
  • 7
  • 1
    You can only `await` a promise. Surely there's some kind of `.toPromise` method on observables? – Bergi Jan 19 '18 at 17:55
  • Not sure about the duplicate tag, the other answer has no reference to async/await. May have been better to post an actual answer than an implied one. – Richard Matsen Jan 19 '18 at 21:43

0 Answers0