As a newcomer to Angular2, I'm struggling to understand how http requests work in this framework. Despite following tutorials and experimenting with both promises and observables, I can't seem to get the json response to display in my component. The data just won't show up.
Here's my code:
private doAction() {
this.doHttpRequest().subscribe(
data => this.content = data
);
this.content = JSON.stringify(this.content);
}
private doHttpRequest() {
return this.http.get('http://jsonplaceholder.typicode.com/posts/1')
.catch(this.handleError);
}
The variable this.content is linked to my template. When I trigger the doAction() method by clicking a button, I initially see an empty string in the template for a second, then it changes to [object Object] after another second.
Can anyone pinpoint what's causing this issue?