Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Http.Post - How to view webapi response

I'm new to Angular2/Typescript and I'm writing my first web application.

I'm trying to call a webapi using POST, it works, if I intercept the call using FIDDLER I can see the Json response.

Now, how I can log in the browser console the json ouput?

The code is this:

code call

var s = this.myService.doSearch();
s.subscribe(
    data=> this.data = data,
    error => this.errorMessage = <any>error
);

console.log(s);

service method

doSearch() {
var url = this.baseUrl;

return this.http.get(url)
    .map(response => response.json())
    .catch(this.handleError);
}

My question is: how and where I can view and manage the Json Output ?

Thanks

like image 353
DarioN1 Avatar asked Jun 15 '26 04:06

DarioN1


1 Answers

You need to console.log it after the async code is finished:

var s = this.myService.doSearch();
s.subscribe(
    data=> {
          this.data = data;
          console.log(data);
    },
    error => this.errorMessage = <any>error
);
like image 115
Mario Petrovic Avatar answered Jun 17 '26 23:06

Mario Petrovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!