Http uses rxjs and is a cold/lazy observable, meaning that you should subscribe to it to make it work.
this.http.get(`http://swapi.co/api/people/1`).map((response:Response) => {
console.log(response.json());
response.json();
}).subscribe();
Or if you want to subscribe from somewhere else , you should return the http.get method like this : :
getAllPersons():Observable<any>{
console.log("Here");
return this.http.get(`http://swapi.co/api/people/1`).map((response:Response) => {
console.log(response.json());
response.json();
});
}
and then :
getAllPersons().subscribe();
No comments:
Post a Comment