Angular 2 Http.get没有响应 [英] Angular 2 Http.get not responding

查看:106
本文介绍了Angular 2 Http.get没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Http.get来检索配置文件.我已经成功完成了很多次,但是这次没有任何结果.即使在使用.catch,我也没有在控制台中看到跟踪,也没有看到错误.我在这里可能是什么问题?

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

推荐答案

您需要具有 subscribe() 才能接收数据

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

这篇关于Angular 2 Http.get没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆