Angular 4 Error: No provider for HttpClient

后端 未结 5 1371
北恋
北恋 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:42

    For this you have to import the following:

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

    And for the spec file in the configureTestingModule of your test, do the following:

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

提交回复
热议问题