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]:
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 : [
    //...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.

๐Ÿ‘‹ 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 which was acquired by Upmostly in July 2022.

๐Ÿ’ฌ Leave a comment

Your email address will not be published.

We will never share your email with anyone else.