基本要求
以下示例演示了一個簡單的 HTTP GET 請求。http.get() 返回 Observable,其方法為 subscribe。這個將返回的資料附加到 posts 陣列。
var posts = []
getPosts(http: Http):void {
this.http.get(`https://jsonplaceholder.typicode.com/posts`)
.map(response => response.json())
.subscribe(post => posts.push(post));
}