2

I'm using Http.get to retrieve a configuration file. I've done this many times with success, but this time nothing. I'm not seeing the trace in my console, and I'm not seeing an error either, even though I am using .catch. What might be my problem here?

this._http.get('./assets/dashboard/json/config.json')
  .map((response: Response) => {

    console.log(response.json());

  })
  .catch((error: any) => Observable.throw(error || 'Server error'));
BBaysinger
  • 6,614
  • 13
  • 63
  • 132

2 Answers2

3

You need to have subscribe() in order to recieve the data

   this._http.get('./assets/dashboard/json/config.json')
        .map(res => res.json())
        .subscribe(
          data => this.ResResponse= data,
          err => this.logError(err),
          () => console.log('Completed')
        ); 

    logError(err) {
      console.error('There was an error: ' + err);
    }
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Thanks. Could you fix this example so it is working. Then I may select it as the correct answer. Also, I would like to add a 'catch' as well. Where would I do that. – BBaysinger Apr 17 '17 at 16:48
2

you need to call subscribe() in order that the request is executed.

René Winkler
  • 6,508
  • 7
  • 42
  • 69