mayyya
mayyya

Reputation: 17

ERROR NullInjectorError: R3InjectorError Standalone NullInjectorError: No provider for HttpClient

Im getting this error:

ERROR NullInjectorError: R3InjectorError(Standalone[_LoginComponent])[HttpClient -> HttpClient -> HttpClient -> HttpClient]: 
  NullInjectorError: No provider for HttpClient! in angular. 

Here is my code : enter image description here

enter image description here

enter image description here

enter image description here

[package.json[app.module.ts[login.component.ts]

I don't know what I am doing wrong. Do I have to import or provide HttpClient somewhere else or in my Login component? I tried to provide it in my component and then i get the same error message but it says that there is no provider for HttpHandler.

Upvotes: 0

Views: 3420

Answers (1)

Naren Murali
Naren Murali

Reputation: 58174

Since login.component is standalone, you need to import HttpClientModule to the imports array!

ERROR NullInjectorError: R3InjectorError(Standalone[_LoginComponent])[HttpClient -> HttpClient -> HttpClient -> HttpClient]: NullInjectorError: No provider for HttpClient! in angular.

  1. Login component has the problem
  2. HttpClient, belongs to HttpClientModule - hence we need to import this module inorder to use it!

If login.component is a standalone component, then it should not be present in the declarations array of any module! it should be in imports array!

Upvotes: 1

Related Questions