Angular NullInjectorError beheben: No provider for HttpClient!
English
Deutsch
Falls Sie den folgenden Fehler für Ihre Angular-Anwendung in Ihrer JS-Konsole sehen:
angular_nullinjector_error_output.txt
main.ts:6 ERROR NullInjectorError: R3InjectorError(AppModule)[MyService -> HttpClient -> HttpClient -> HttpClient]:
NullInjectorError: No provider for HttpClient!
at NullInjector.get (core.mjs:7599:27)
at R3Injector.get (core.mjs:8020:33)
at R3Injector.get (core.mjs:8020:33)
at R3Injector.get (core.mjs:8020:33)
at injectInjectorOnly (core.mjs:634:33)
at Module.ɵɵinject (core.mjs:638:60)
at Object.MyService_Factory [as factory] (my.service.ts:8:38)
at R3Injector.hydrate (core.mjs:8121:35)
at R3Injector.get (core.mjs:8009:33)
at ChainedInjector.get (core.mjs:12179:36)müssen Sie HttpClientModule zu Ihrer app.module.ts hinzufügen.
Importieren Sie zuerst HttpClientModule am Anfang von app.module.ts:
app.module.ts
import { HttpClientModule } from '@angular/common/http';Fügen Sie danach
app.module.ts
HttpClientModule,zum imports: [...]-Abschnitt Ihres @NgModule hinzu, zum Beispiel:
app.module.ts
@NgModule({
declarations: [
AppComponent,
],
imports: [
HttpClientModule,
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }Danach sollte Ihr Fehler verschwunden sein
Check out similar posts by category:
Angular, Typescript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow