The following example demonstrates a simple HTTP GET request. http.get()
returns an Observable
which has the method subscribe
. This one appends the returned data to the posts
array.
var posts = []
getPosts(http: Http): {
this.http.get(`https://jsonplaceholder.typicode.com/posts`)
.subscribe(response => {
posts.push(response.json());
});
}