Search code examples
angularasynchronousbehaviorsubjectangular4-httpclient

Angular 4, difference between httpClient and HttpClientModule


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?


Solution

  • 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.