静态注入器错误[e -> e]:NullInjectorError:e没有提供程序。

7

在我的app.module.ts文件中

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    MaterialModule,
    FlexLayoutModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    MyAppModule
  ],
  providers: [
    AuthenticationService,
    AuthGuardService,
    MyAppService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

在我的AuthGuardService中:

@Injectable({
  providedIn: 'root'
})
export class AuthGuardService implements CanActivate {

我已经添加了HttpClientModule甚至在我的authguard中加入了providedIn,但仍然遇到此错误。我正在使用Angular 7。

1个回答

4

如果您已经添加了providedIn: 'root',请从提供商中删除所有服务。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接