简体   繁体   English

Angular 2 Http.get没有响应

[英]Angular 2 Http.get not responding

I'm using Http.get to retrieve a configuration file. 我正在使用Http.get来检索配置文件。 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. 我没有在控制台中看到跟踪,也没有看到错误,即使我使用的是.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 您需要具有subscribe()才能接收数据

   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()才能执行请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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