Javascript NullInjectorError:没有自定义组件的提供程序-添加到提供程序不会';行不通

Javascript NullInjectorError:没有自定义组件的提供程序-添加到提供程序不会';行不通,javascript,angular,typescript,Javascript,Angular,Typescript,我在尝试测试时出现错误 我已经阅读了许多类似的相关问题,但是将我的自定义LoginComponent添加到app.module.ts提供程序中没有帮助?它已经在导入部分中 应用程序模块.ts @NgModule({ declarations: [ AppComponent, LoginComponent, ], imports: [ BrowserModule, FormsModule, HttpClientModule ], prov

我在尝试测试时出现错误

我已经阅读了许多类似的相关问题,但是将我的自定义LoginComponent添加到app.module.ts提供程序中没有帮助?它已经在导入部分中

应用程序模块.ts

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: AppHttpInterceptor,
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
login.component.spec.ts(摘要)


我发现需要将我的LoginComponent放在
声明
提供者
部分,从而解决了这个问题

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [LoginComponent],
      imports: [FormsModule, HttpClientModule],
      providers: [LoginComponent]
    }).compileComponents();

    fixture = TestBed.createComponent(LoginComponent);
    component = fixture.componentInstance;
  }));

我发现需要将我的LoginComponent放在
声明
提供者
部分,从而解决了这个问题

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [LoginComponent],
      imports: [FormsModule, HttpClientModule],
      providers: [LoginComponent]
    }).compileComponents();

    fixture = TestBed.createComponent(LoginComponent);
    component = fixture.componentInstance;
  }));

实际误差是什么?从哪里得到的?实际误差是什么?从哪里得到的?