When I try to use my service I get the following error:
Uncaught (in promise): NullInjectorError: R3InjectorError(HomePageModule)[ApiService -> ApiService -> HttpClient -> HttpClient -> HttpClient]:
NullInjectorError: No provider for HttpClient!
I have correctly imported the HttpModule in app.module.ts:
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [HttpClientModule, BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy}],
bootstrap: [AppComponent],
})
And my service is loaded in me main page constructor like this:
constructor(
public serv: ApiService,
){ }
What I’m doing wrong? Thanks in advance!
I’m using Ionic 6.17.1, on Windows 11
Edit:
This is my service class code:
import { Injectable } from '@angular/core';
import {HttpClient, HttpClientModule, HttpHeaders, HttpErrorResponse} from '@Angular/common/http'
import { Observable, throwError } from 'rxjs';
import {retry, catchError} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ApiService {
//API path
base_path='http://localhost:3000/';
constructor(private http: HttpClient) { }