ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]:
Make sure you have imported HttpClientModule
instead of adding HttpClient
direcly to the list of providers.
See https://angular.io/guide/http#setup for more info.
The HttpClientModule
actually provides HttpClient
for you. See https://angular.io/api/common/http/HttpClientModule:
Code sample:
import { HttpClientModule, /* other http imports */ } from "@angular/common/http";
@NgModule({
// ...other declarations, providers, entryComponents, etc.
imports: [
HttpClientModule,
// ...some other imports
],
})
export class AppModule { }
Import this in to app.module.ts
import {HttpClientModule} from '@angular/common/http';
and add this one in imports
HttpClientModule
In my case there was a need for:
@Injectable({
providedIn: 'root' // <- ADD THIS
})
export class FooService { ...
instead of just:
@Injectable()
export class FooService { ...