Two base classes are defined as follows:
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(){
}
}
A component class needs to make use of the above two classes.
export class addNewEmployeeComponent(){
constructor(){
}
}
An attempt was made to use the applyMixins solution for extending multiple classes, but the definition of super() for the base class while extending two classes is unclear. An error was encountered when trying to use the AddNewEmployee mixin in the 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]);
A mixin was created with the given code, but it is unclear how the AddNewEmployee class can be used in the AddNewEmployeeComponent.
The situation involves the need to use two classes in a component, but multiple inheritance is not an option. Any alternative solutions are welcome.
A reference was made to this question but the accepted answer was not fully understood.
Thank you!