I'm new to Angular and following this tutorial to learn the basics. Consider the following http get call.
getHeroes(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
}
After converting the observable to a promise, how can I really utilize the response(e.g. console log, parse and access a response element.. etc) using a function inside the then() clause?
I tried the following, even though it logs the Response, I can't really access anything in the response object.
this.http.get(url, {headers : this.headers})
.toPromise()
.then(function(res) {
console.log(res);
return res => res.json().data as Query[];
})
.catch(this.handleError);
Any help would be much appreciated. Thank you.