Amit
Amit

Reputation: 1560

How can get HttpClient Status Code in Angular 4

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.

Upvotes: 47

Views: 55732

Answers (1)

Andy Danger Gagne
Andy Danger Gagne

Reputation: 2227

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.

Upvotes: 83

Related Questions