Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can get HttpClient Status Code in Angular 4

Tags:

angular

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.

like image 987
Amit Avatar asked Oct 09 '17 05:10

Amit


1 Answers

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.

like image 129
Andy Danger Gagne Avatar answered Oct 18 '22 19:10

Andy Danger Gagne