http.get不打电话,Angular 2

时间:2016-04-25 19:47:18

标签: http get angular

我正在玩角度2,我发送http get请求有问题。 我创建了这样的方法:

  test(){
     console.log("call test");
     let header =  new Headers();
     header.append("authorization",'change9ziKuJH8wnVbNES3AMleYGPKzZ');

     this._http.get('http://localhost:42055/api/Question',{headers:header}).do(res => console.log("Result: " + JSON.stringify(res)));

}

主要问题是,此http请求从未发送过。我看着小提琴手,我的localhost没有请求:42055。

不幸的是,Angular没有显示任何错误,所以我不知道会发生什么错误。

1 个答案:

答案 0 :(得分:4)

Observables是懒惰的,所以你需要订阅它们才能实际执行相应的处理(在你的情况下是HTTP请求):

this._http.get('http://localhost:42055/api/Question',{headers:header})
   .do(res => console.log("Result: " + JSON.stringify(res)))
   .subscribe((res) => { // <-------------
     // handle result
   });
相关问题