Angular 4 Error: No provider for HttpClient
An easier way is to provide it globally....Import the following into app.module.ts like so:
import { HttpModule } from '@angular/http'
import { HttpClient, HttpClientModule } from '@angular/common/http';
and declare it in imports:
imports: [
HttpModule,
HttpClientModule, ...
]
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();
In your test
TestBed.configureTestingModule({
providers: [FlexSearchService, HttpClientModule]
});
It should be
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [FlexSearchService]
});
or even better (if you want to mock request):
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [FlexSearchService]
});
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();