Angular 4 Error: No provider for HttpClient

后端 未结 5 1344
北恋
北恋 2020-12-25 09:40

I am starting a new angular project with the CLI and am running into a no provider for HttpClient error.

I have added HttpClientModule to m

5条回答
  •  醉梦人生
    2020-12-25 10:34

    Import HttpClientTestingModule.

    In your test:

    import { HttpClientTestingModule } from '@angular/common/http/testing';
    

    and in the configureTestingModule of your test, do the following:

    TestBed.configureTestingModule({
        imports: [ HttpClientTestingModule ],
    })
    .compileComponents();
    

提交回复
热议问题