Reputation: 47
I am playing with angular 2 and I have problem with sending http get request. I created method like this:
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)));
}
The main problem is that, this http request never was send. I look at the Fiddler and there is no request to my localhost:42055.
Unfortunately Angular don't display any errors, so I don't have any clue what is going one.
Upvotes: 1
Views: 585
Reputation: 202326
Observables are lazy so you need to subscribe them to actually execute corresponding processing (HTTP requests in your case):
this._http.get('http://localhost:42055/api/Question',{headers:header})
.do(res => console.log("Result: " + JSON.stringify(res)))
.subscribe((res) => { // <-------------
// handle result
});
Upvotes: 4