[NullInjectorError]: R3InjectorError(Standalone[_AppComponent])[]: NullInjectorError: No provider for _HttpClient

201 Views Asked by At

app.module.ts

app.module.ts

app.module.ts

Error

package.json

My code is migrated to angular standalone 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.

1

There are 1 best solutions below

3
Naren Murali On BEST ANSWER

Since App Component is a standalone component, you can simply add the AppModule to the imports array of AppComponent.

@Component({
  ...
  standalone: true,
  imports: [AppModule]
  ...
})
export class App {
...

Also ensure that in the provideHttpClient you are giving this

import { provideHttpClient } from '@angular/common/http';

bootstrapApplication(App, {
  providers: [provideHttpClient()]
});

Ensure you have loginService added to the providers of either App Component this might fix your issue!