In my abstract class, I have defined all my http
calls. However, when I try to extend this class in child services, I encounter a compile time error.
Can't resolve all parameters for MyService : (?).
baseservice.ts
import { HttpClient, HttpHeaders } from '@angular/common/http';
export abstract class BaseService{
constructor(private http: HttpClient){} //http undefined on compile time
get(){
return this.http.get()
}
}
myservice.ts
@Injectable()
export class MyService extends BaseService{
getSource() {
return this.get('api/Source')
}
}
When additional injectTokens are included in the constructor of the abstract class, it results in a not defined
error
constructor(private http: HttpClient, @Inject(APP_CONFIG) private appConfig: any | undefined) {}
Uncaught ReferenceError: http_1 is not defined
If Options are added, initializing the HttpClient and everything works correctly
HttpOptions = {
headers: new HttpHeaders({
'Authorization': `Bearer ${this.token}`
})
What could be causing this issue and how can it be resolved while creating an instance of HttpClient
without any InjectTokens
or httpOtions
.