【问题标题】:Generic type 'ComponentRef<C>' requires 1 type argument(s)通用类型 'ComponentRef<C>' 需要 1 个类型参数
【发布时间】:2016-11-03 08:22:54
【问题描述】:

无法删除 ionic-2 中的动态组件。打字稿编译时出现异常

“通用类型 'ComponentRef' 需要 1 个类型参数”。

此外,在不使用 ionic2 的情况下使用相同的代码。 非常感谢您的帮助。 提前致谢。

class DynamicCmp {
  _ref: ComponentRef;
  _idx: number;
  constructor(private resolver: ComponentResolver, private location: ViewContainerRef) { }
  remove() {
    this._ref.destroy();
  }
  add1() {
    this.resolver.resolveComponent(DynamicCmp).then((factory: ComponentFactory<any>) => {
      let ref = this.location.createComponent(factory, 0);
      ref.instance._ref = ref;
      ref.instance._idx = this._idx++;
    });
  }
}

异常:TypeScript 错误:....../home/home.ts(9,11): Erro r TS2314:通用类型“ComponentRef”需要 1 个类型参数。

【问题讨论】:

    标签: angular ionic2 angular2-components


    【解决方案1】:

    ComponentRef 是泛型类型。只需将您的代码更改为以下内容:

    class DynamicCmp {
      _ref: ComponentRef<any>; <== add <any>
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2017-06-05
      • 2017-10-23
      • 2022-12-19
      • 2018-12-08
      • 1970-01-01
      • 2017-01-09
      • 2017-02-08
      • 2020-12-06
      • 2021-10-24
      相关资源
      最近更新 更多