This is such a simple error but one that catches me out on every single new project it seems. The full error is :
Error: StaticInjectorError[HttpClient]:
StaticInjectorError[HttpClient]:
NullInjectorError: No provider for HttpClient!
Unfortunately it’s not that descriptive, but it’s an easy fix.
In your app.module.ts, you need to import the HttpClientModule.
Simply add the import at the top of the file :
import { HttpClientModule } from '@angular/common/http';
And then in the imports section, add the HttpClientModule :
imports : [
HttpClientModule,
//...Other Modules Here...
]
And that’s it! You only need to do this in the root AppModule and don’t need to reimport it elsewhere in other modules within your app.
💬 Leave a comment