Привет, вот недавно я пытался использовать наследование для репликации некоторых из моих классов компонентов, которые мне удалось использовать для вызова компонента наследования, поскольку в качестве модуля маршрутизации не было ошибок и при успешной загрузке родительский и дочерний компоненты, но при попыткевызвал мой компонент как Компонент, используя селектор, такой как в режиме AOT, он не распознал их как компонент и там есть ошибка:
'app-supplier-child' is not a known element:
1. If 'app-supplier-child' is an Angular component, then verify that it is part of this module.
2. If 'app-supplier-child' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("el[2]" >
<!-- <ng-template #viewSupplierChild></ng-template> -->
[ERROR ->]<app-supplier-child #supChild></app-supplier-child>
</p-tabPanel>
")
Это то, что я работал до сих пор:
=============== child component ======================
@Inherit({
selector: 'app-supplier-child',
})
export class SupplierChildComponent extends SuplierParentComponent implements OnInit, AfterViewInit {
....
}
============ parent component ==================================
@Component({
selector: 'app-suplier-parent',
template: `...`
})
export class SuplierParentComponent implements OnInit, ButtonActionListener{
....
}
================== inherit function ==========================
export function Inherit(extendedConfig: Component = {}) {
return function (target: Function) {
const annotations = target[ANNOTATIONS] || [];
if (annotations.length > 0) {
const parentAnnotations = Object.assign({}, annotations[0]);
Object.keys(parentAnnotations).forEach(key => {
if (parentAnnotations.hasOwnProperty(key)) {
if (!extendedConfig.hasOwnProperty(key)) {
extendedConfig[key] = parentAnnotations[key];
} else {
if('template'.equals(key)) {
extendedConfig[key] = parentAnnotations[key].concat(extendedConfig[key]);
} else {
extendedConfig[key] = extendedConfig[key];
}
}
}
});
}
const component = Component(extendedConfig)(target);
return component;
};
}