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 being called.
The program is going to that method console logging above and below that get call but nothing for the get call
My service method
import { Headers, Http, Response } from '@angular/http';
import { Injectable } from '@angular/core';
import { Persons } from './mock-people';
import { Person } from './person';
import {Observable} from 'rxjs/Rx';
getAllPersons(): void {
console.log("Here");
this.http.get(`http://swapi.co/api/people/1`)
.map((response: Response) => {
console.log(response.json());
response.json();
});
console.log("Comes here 2");
}
Imported HttpModule
in app.module.ts
My console Screen shot
Http uses rxjs and is a cold/lazy observable, meaning that you should subscribe to it to make it work.
Or if you want to subscribe from somewhere else, you should return the
http.get
method like this:and then :