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.

Wade Developer
👋 Hey, I'm Wade
Wade is a full-stack developer that loves writing and explaining complex topics. He is an expert in Angular JS and was the owner of tutorialsforangular.com which was acquired by Upmostly in July 2022.

💬 Leave a comment

Your email address will not be published. Required fields are marked *

We will never share your email with anyone else.