I have two base classes which have structure some what as below shown examples:
export class EmployeeSearch(){
constructor(
public employeeService: EmployeeService,
public mobileFormatPipe: MobileFormatPipe
)
searchEmployeeById();
searchEmployeeByName();
}
export class EmployerSearch(){
constructor(
public employerService: EmployerService,
public mobileFormatPipe: MobileFormatPipe,
public employerNamePipe: EmployerNamePipe
)
getAllEmployers(){
}
getLocalEmployers(){
}
}
I have a component class where I want to use above two classes.
export class addNewEmployeeComponent(){
constructor(){
}
}
I tried using applyMixins solution to use interface to extend multiple classes. but I don't know how to define super() for base class while extending two classes and encountered error when I tried using AddNewEmployee mixin class in component.
import { EmployeeSearch } from './employee-search';
import { EmployerSearch } from './employer-search';
export class AddNewEmployee{
}
export interface AddNewEmployee extends EmployeeSearch, EmployerSearch{
}
function applyMixins(derivedCtor: any, baseCtors: any[]) {
baseCtors.forEach(baseCtor => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name));
});
});
}
applyMixins(SearchPatient, [PatientSearch, DepartmentDoctorSelect]);
I have created a mixin using above code but don't know how I can use class AddNewEmployee in AddNewEmployeeComponent.
My use case is that I have two classes which I need to use in my component, but multiple inheritence is not possible. Please suggest some other solution for my use case if any.
I referred this question but couldn't understand the accepted answer.
Thanks!