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?
Angular 4, difference between httpClient and HttpClientModule
Asked Answered
The second part could be a new question –
Adorn
Do you think I should edit out the second part and make another post? –
Rochelrochell
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.
That explains it. Tentatively marked it as the best answer. Gonna wait a little and see if anyone wanna fill in on the 2nd question. (or make another post for that). Thank you. –
Rochelrochell
Better to have another post for 2nd question. :) –
Siegfried
Thanks for the answer but then why is the address same for both, i mean why doesn't the import statement for "
HttpClient
" look like this " import { HttpClient } from '@angular/common/http/HttpClientModule'
" –
Strephon © 2022 - 2024 — McMap. All rights reserved.