Wednesday, April 27, 2022

NullInjectorError: No provider for HttpClient!

From my angular application I tried call rest API backend. So I tried to use HttpClient to make a get call to API. The application complied successfully, but UI page was not loaded with html element, I saw only empty page. In console I find below error, error is very clear, I missed to import HttpClientModule in my AppModule.ts file.

Error thrown code snippet below, 
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
],

NullInjectorError: No provider for HttpClient! 


After import HttpClientModule, the html page loaded perfectly.
import {HttpClientModule} from '@angular/common/http';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],

Thank you.

No comments:

Post a Comment