-2

My Component:

getDetailsByPhone(phone: any) {
        this.phoneSearchDetails = this.appService.manageHttp('get', 'search?number='+phone, '');
 }

My service:

manageHttp(method: any, url: any, body: any) {
    this.headers = this.config.setHeaders();
    var urlto = this.config.serverUrl +''+url;

    return  this.http.get(urlto,{ headers: this.headers }).map((response: Response) => {
            return response.json();
        });
}

With this code I am not able to see the response going in network.I am not sure about whats wrong and I didnt see any error in console.Can anyone please suggest help.Thanks.

Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175
MMR
  • 2,869
  • 13
  • 56
  • 110
  • 2
    Possible duplicate of [Angular 2 http get not getting](https://stackoverflow.com/questions/41381200/angular-2-http-get-not-getting) – 0mpurdy Jul 23 '17 at 14:34

1 Answers1

1

You must subscribe to the observable or it won't fire since it's lazy:

this.appService.manageHttp('get', 'search?number='+phone, '').subscribe((res) => {

  this.phoneSearchDetails = res;

  console.log(res);
}, (err) => {
  // handle error
});

Also as you can see I assign the value of phoneSearchDetails inside the callback of the subscribe since you can't return anything from a subscribe.

Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175