2016-04-25 106 views
1

我正在玩角2,我有发送http请求的问题。 我创建的方法是这样的:http.get不要拨打电话,Angular 2

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请求从来没有发送。我看着提琴手,并没有要求我的本地主机:42055。

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

回答

4

观测值都懒的,所以你需要订阅他们实际执行相应的处理(在你的情况HTTP请求):

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