【问题标题】:Child component doesn't inherit input but the other do子组件不继承输入,但另一个继承
【发布时间】:2019-07-20 01:34:41
【问题描述】:

我有一个“几乎”从其他组件复制粘贴的组件。

我的第一个组件继承与输入一起工作,但不是第二个。

然后我得到一个错误提示

Can't bind to 'anInput' since it isn't a known property of 'my-copied-component'.


<my-copied-component
    [anInput]="someInputValue" <--- ERROR
>
</my-copied-component>

<my-original-component
    [anInput]="someInputValue" <--- Works fine
>
</my-original-component>

实现:

export class MyCopiedComponent extends MyComponentsBase implements OnInit {

基本实现:

export class MyComponentsBase implements OnInit {

@Input() public anInput: string;

我在构造函数中有 super()。

【问题讨论】:

  • 我们能否看到更多来自MyComponentsBaseMyCopiedComponent 的代码?特别是它们上面的组件装饰。

标签: angular typescript inheritance extends


【解决方案1】:

确保您已在模块中声明新组件 -

@NgModule({
  declarations: [MyCopiedComponent]
})
export class SomeModule {}

【讨论】:

  • 这就是答案,谢谢。我是 Angular 的新手,所以我不知道这会影响它。
  • 然后将其标记为已接受;)不客气,乐于助人!
  • 我会在 7 分钟内完成,直到那时:P
  • 是的,我想发表评论,但不允许低于 50rep。现在用一些代码编辑!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 2020-10-07
  • 2019-11-27
  • 1970-01-01
相关资源
最近更新 更多