[英]Input properties in inherited angular 2 components
我試圖通過繼承一些具有一些 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;
}
這一切都按預期工作,直到我在派生組件中添加一個新的 Input 屬性(在提供的示例中是虛擬的)。 當我這樣做時,基類中定義的所有 Input 屬性在運行時都變得不可見(盡管在編譯時一切正常),並且瀏覽器控制台中出現錯誤,指出這些輸入不存在:
無法綁定到 'text',因為它不是 'derived-comp' 的已知屬性。
有沒有人在 angular 2 中遇到過類似的組件繼承問題? 有沒有人有關於如何克服它的建議(除了代碼的復制粘貼)?
也許在舊的 Angular 版本中這是一個 pia,但現在它很容易。 看到這個帖子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.