In this article here and others :It looks like you need to import HttpClientModule in app.module.ts and HttpClient in app.component.ts to make a http request. Why? How do they work?
"HttpClient is an evolution of the existing Angular HTTP API, which exists alongside of it in a separate package...". The tutorial uses HttpModule and angular.io/guide/http uses HttpClientModule and neither explains when one or the other should be used or what version of Angular is needed to use what.
They both support HTTP calls but HTTP is the older API and will eventually be deprecated. The new HttpClient service is included in the HttpClientModule that used to initiate HTTP request and responses in angular apps. The HttpClientModule is a replacement of HttpModule.
The HttpClient is used to perform HTTP requests and it imported form @angular/common/http. The HttpClient is more modern and easy to use the alternative of HTTP. HttpClient is an improved replacement for Http. They expect to deprecate Http in Angular 5 and remove it in a later version.
The HttpClientModule is a service module provided by Angular that allows us to perform HTTP requests and easily manipulate those requests and their responses. It is called a service module because it only instantiates services and does not export any components, directives or pipes.
In simple words,
You can call HttpClientModule as a "feature-bundle" that comes as a core part in Angular. In this "feature-bundle", you have many other small features like HttpClient (in Angular language, it's "service"), Interceptors etc.
In order for you to use these "feature(s)", you need to import the "feature-bundle" inside your main module (in your case, Angular's AppModule) so that, you have access to HttpClient and many other services inside your working component.
One liner:
HttpClient is a angular service bundled inside HttpClientModule.
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