I have a large application on Angular2
which is now ported to Angular4
. However, it still uses the Http
service.
I realize that Angular4
has HttpClient
which is said to be better than Http
service. However, I am but apprehensive about changing to HttpClient
since it is used in many places and corresponding unit tests.
I would like to know, what is the best way to move from Http
to HttpClient
? What things should I consider from code and unit tests point of view?
Another reason I would like to move to HttpClient
is to use the interceptor? Is it necessary to change to HttpClient
for this?
Please advise. Many thanks in advance.
Just my experience.
As I remember my biggest problem was to remove map in each http call.
Otherwise you just need to import HttpClientModule and inject HttpClient service instead of Http.
Also, there is some changes in unit testing. So if you have unit tests you have a bit more work. With HttpClient
unit testing became much easier. Angular has great docs there, so I don't think it will be big problem. At least for me I did not have any problems with understanding this new stuff.
You can check this article for more information: http://brianflove.com/2017/07/21/migrating-to-http-client/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With