I am having hard time understanding Angular2 Http(Observable) methods:
Here is my code:
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 || { };
}
My Question is : Why do we need subscribe method, if we can extract the data and everything else in a map method of an Observable ?
Thanks