I have been able to create a working application. But I am getting an error when I am using the abstract class (ClientService) as type and then using it with useClass.
Before I start, let me explain the design.
-
app.moduleis the main app module. -
I have a dynamic module (
external.module.ts) that can be configured dynamically to show different types of planet dashboards. -
I have created
mars-dashboard.modulewhich basically wrapsexternal.module.tsinside it and sends the configuration forexternal.module.tsto work accordingly. -
I have created an abstract class (inside
external.module)ClientServicewhich has some methods asabstract. It is upto themars-dashboard.moduleto decide what payload should be prepared forMarsplanet for those respective methods. This is achieved by extending it toMyAppClientService -
There can be some methods which have same response across Planets, therefore they are implemented in our abstract class. They are just for display purpose.
Everything works as expected. The problem comes when I set the type of ClientService in external.module.ts:
external.module.ts
export class ExternalModule {
static forRoot<T>(config: {
name: string;
clientService: any; //TODO: add type which creates problem
}): ModuleWithProviders<ExternalModule> {
return {
ngModule: ExternalModule,
providers: [
{
provide: CLIENT_SERVICE,
useClass: config.clientService // useClass does not accept abstract class
},
{
provide: DASHBOARD_NAME,
useValue: config.name
}
]
};
}
}
Question:
-
How should I design this so that the angular
typealso approves my implementation. -
Is there a better way to solve this design challange?
Please note, in actual implementation, the external.module is a separate lib which I have created using Nx
Aucun commentaire:
Enregistrer un commentaire