It has come to my attention that my services are quite repetitive. In an attempt to enhance them, I decided to delve into super classes and inheritance in Angular. However, I have been struggling with the constructor and super calls. Despite TypeScript compiling without any errors, I am encountering the following issue in the console:
core.js:12632 ERROR Error: Uncaught (in promise): TypeError: this.http.get is not a function
I predict that similar problems will arise with all of my dependencies.
Below is my BaseService Class:
import {EventEmitter, Output} from '@angular/core';
import { environment } from '../../environments/environment';
export abstract class BaseService {
@Output() saving = new EventEmitter();
constructor(
public api_url: string,
public success_message: string,
public success_url: string,
public nav_to_view: boolean,
public http,
public toaster,
public router,
) {
this.api_url = environment.api + this.api_url;
}
list() {
return this.http.get(this.api_url);
}
}
And here is the service that extends BaseService:
import {Injectable} from '@angular/core';
import {BaseService} from '../../core/base.service';
import {HttpClient} from '@angular/common/http';
import {ToastrService} from 'ngx-toastr';
import {Router} from '@angular/router';
@Injectable()
export class ModulesService extends BaseService {
constructor() {
super('/modules', 'Manufacturer Saved!', '/modules', false, HttpClient, ToastrService, Router);
}
}
What am I missing? Your help is greatly appreciated!