【问题标题】:Upgrading to Angular 9 using Ivy, cannot combine @Input decorators with query decorators (@ContentChild) [duplicate]使用 Ivy 升级到 Angular 9,无法将 @Input 装饰器与查询装饰器 (@ContentChild) 结合使用 [重复]
【发布时间】:2020-03-18 13:49:47
【问题描述】:

升级到 Angular 9 我收到以下与包相关的错误:

Compiling @ngx-package : es2015 as esm2015

ERROR in Failed to compile entry-point @ngx-package (es2015 as esm2015) due to compilation errors:
node_modules/@ngx-package/@ngx-package.js:1325:34 - error NG1006: Cannot combine @Input decorators with query decorators

1325     'actions': [{ type: Input }, { type: ContentChild, args: [Component,] },],

这个错误的负责代码如下:

@Input() @ContentChild(Component) actions: Component;

【问题讨论】:

  • 搜索该错误消息会引发其他类似问题的问题。不知道为什么这需要一个自我回答的问题? stackoverflow.com/questions/56457566/…
  • 你说得对,我没有看到这个问题,我正在那里回答。
  • 已经回答了吗?
  • 部分,我认为我的回答会给出这个案例解决方案的具体例子,不是吗?
  • 这是一个具体的解决方法,但您可能有充分的理由应该避免这样做。原始代码的用例是什么?

标签: angular typescript angular9


【解决方案1】:

问题是我不能合并@Input()@ContentChild,所以我用以下代码替换了导致错误的代码:

get actions(): Component {
  return this._actions;
}

private _actions: Component;

@Input()
set actions(value: Component) {
  this._actions = value;
}

@ContentChildren(Component)
set viewActions(value: Component) {
  if (!this._actions && value) {
    this._actions = value;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2013-12-06
    • 2011-10-04
    • 2018-04-14
    • 2021-07-30
    • 1970-01-01
    • 2019-10-20
    相关资源
    最近更新 更多