I want to define a base class for my components to share some features. So i've began with :
export abstract class BaseComponent {
protected getName(): string;
}
@Component(...)
export class MyComponent extends BaseComponent {
protected getName(): string {
return "MyComponent";
}
}
But after i needed to add some annotations to BaseComponent like @HostListener('window:keydown', ['$event'])
. So i had to add @Component
to BaseComponent
to enable angular annotations. Everything was good... Until i tried to compile in production mode with
ng build --prod
:
Cannot determine the module for class BaseComponent
So i've added BaseComponent
to @NgModule
, but i had :
No template specified for component BaseComponent
So i've added
@Component({template: ''})
But i had :
Argument of type 'typeof BaseComponent' is not assignable to parameter of type 'Type'. Cannot assign an abstract constructor type to a non-abstract constructor type.
So i had remove the "abstract
" keyword to compile in production mode my project.
Do you have a solution? I dislike bad conception!