I new to Angular 2 still learning I am trying to hit a URL with a get call but the get doesn\'t seem to go through even in browser\'s network I cannot find that get URL bein
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 {
console.log("Here");
return this.http.get(`http://swapi.co/api/people/1`)
.map((response: Response) => {
console.log(response.json());
return response.json();
});
}
and then :
getAllPersons().subscribe();