45
votes

In Http Module I can easily get the response code using response.status, but when I used HttpClient Module I cannot get the response.status, it shows undefined.

So, how can I get the response.status using HttpClient module in Angular 4. Please help.

1
This is all explained here: angular.io/guide/http - Henry
I checked the documentation but I didn't find the exact solution to find the status code from response. - Amit
Look at the section "Reading the full response". - Henry
Thanks for your help... It works now. - Amit

1 Answers

77
votes

From this section, this is the adjusted code

http
  .post<T>('/yoururl', whateverYourPostRequestIs, {observe: 'response'})
  .subscribe(resp => {
     console.log(resp);
  });

the answer is {observe: 'response'}. you can then view the logged resp and pick/choose what you want.