Angular 7 : Injected service is undefined

前端 未结 3 2066
抹茶落季
抹茶落季 2021-02-18 12:50

I tried to inject AccountService in the LoginService but it won\'t ,the accountService is undefined but in the other hand the authServiceProvider is defined .

Contraril

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-18 13:27

    HttpClientModule is required for HttpClient. Just import in AppModule.

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { CoreModule } from './core/core.module';
    import { HttpClientModule } from '@angular/common/http';
    import { MatTreeModule } from '@angular/material';
    import { FormsModule, ReactiveFormsModule } from '@angular/forms';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
        AppRoutingModule,
        CoreModule,
        MatTreeModule,
        FormsModule,
        ReactiveFormsModule,
        HttpClientModule //add this as fix, simple
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

提交回复
热议问题