Neb*_*kov 5 javascript inheritance typescript angular
我试图通过继承一些具有一些Input属性的基类来实现angular 2的组件(我已使用此示例作为实现angular 2组件的继承的指南)。
简化示例
export class ComponentBase {
@Input() text: string = "base";
}
@Component({
selector: "derived-comp",
templateUrl: "derived-comp.template.html",
providers: [
{ provide: ComponentBase, useExisting: forwardRef(() => DerivedComponent) }
]
})
export class DerivedComponent extends ComponentBase {
@Input() dummy: number;
}
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作,直到我在派生组件中添加了一个新的Input属性(虚拟,在提供的示例中)。当我这样做时,基类中定义的所有Input属性在运行时都变得不可见(尽管在编译时一切正常),并且浏览器控制台中出现错误,指出这些输入不存在:
无法绑定到“文本”,因为它不是“ derived-comp”的已知属性。
有没有人在角度2中有类似的组件继承问题?是否有人对如何克服它有建议(除了复制粘贴代码外)?