简体   繁体   中英

Angular 2 Http.get not responding

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'));

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);
    }

您需要调用subscribe()才能执行请求。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM