基本要求
以下示例演示了一个简单的 HTTP GET 请求。http.get() 返回 Observable,其方法为 subscribe。这个将返回的数据附加到 posts 数组。
var posts = []
getPosts(http: Http): {
this.http.get(`https://jsonplaceholder.typicode.com/posts`)
.subscribe(response => {
posts.push(response.json());
});
}