I have the following typescript service code that I wish to expose via a new Angular module.
Generic Service
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Observable } from "rxjs";
import { AuthHeaders } from "./auth.headers";
export abstract class BaseHttpService<T> {
baseAPIUrl: string;
serviceAPISegment: string;
private requestOptions = {
headers: this.authHeaders.getHeaders()
};
constructor(
private httpClient: HttpClient,
private authHeaders: AuthHeaders
) {}
get<T>(): Observable<T[]> {
return this.httpClient.get<T[]>(
`${this.baseAPIUrl}\\${this.serviceAPISegment}`,
this.requestOptions
);
}
}
Module Declaration
import { NgModule } from "@angular/core";
import { HttpClientModule } from "@angular/common/http";
import { BaseHttpService } from "./asyncServices/http/base.http.service";
@NgModule({
imports: [
HttpClientModule
],
declarations: [
BaseHttpService
]
})
export class SharedModule {}
I get error in the BaseHttpService which is given below
ERROR in src/app/shared/shared.module.ts(11,5): error TS2322: Type 'typeof BaseHttpService' is not assignable to type 'any[] | Type'. Type 'typeof BaseHttpService' is not assignable to type 'Type'. Cannot assign an abstract constructor type to a non-abstract constructor type.
I have tried the following BaseHttpService BaseHttpService<>
which all are not working. Please suggest the suitable way to register the service in this module.