Reputation: 39
Scratching my head on this error. 'Error: No provider for HttpParams!' Migrating from Http to HttpClient. Imported HttpClientModule in app.module.ts and made it a member in @NgModule -> imports
There is still an import for HttpModule in app.module.ts. Can it be clashing with the new HttpClientModule?
In my service I have:
import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
Can someone please enlighten me as to why this is happening? TIA, Pedro.
Upvotes: 3
Views: 4038
Reputation: 27
If you are using this [params: HttpParams]
in your constructor, please remove it from the constructor.
import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class MarksService {
constructor(private http: HttpClient, private params: HttpParams) {}
}
Upvotes: 3
Reputation: 61
You are getting error for HttpClient
so, you are missing HttpClientModule
for that.
you should import it in "app.module.ts" file like this:
import { HttpClientModule } from '@angular/common/http';
and mention it in the NgModule
decorator like this:
@NgModule({
...
imports:[ HttpClientModule ]
...
})
if this even doesn't work try clearing cookies of the browser and try restarting your server. Hopefully it may work, I was getting the same error.
Upvotes: 3