我有很難理解Angular2 HTTP(可觀察)方法:爲什麼我們需要用戶的方法:Angular2
這裏是我的代碼:
login(username:string,password:string) {
let headers = new Headers();
this.createAuthorizationHeader(headers,username,password);
return this.http
.get(this.url,{headers:headers})
.map(this.extractData)
.catch(this.handleError).subscribe(e => console.log(e));
}
private extractData(res: Response) {
let body = res.json();
console.log(body);
return body.data || { };
}
我的問題是:我們爲什麼需要訂閱方法,如果我們可以提取Observable的地圖方法中的數據和其他所有內容?
謝謝