Generic type 'ComponentRef<C>' requires 1 type argument(s)

倖福魔咒の 提交于 2019-12-01 03:17:26

问题


Unable to remove dynamic components in ionic-2. It’s saying exception while typescript compile

“Generic type 'ComponentRef' requires 1 type argument(s)”.

Also, the same code is working while using without using ionic2. Much appreciate your help. Thanks in Advance.

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++;
    });
  }
}

Exception: TypeScript error: ....../home/home.ts(9,11): Erro r TS2314: Generic type 'ComponentRef' requires 1 type argument(s).


回答1:


ComponentRef is a generic type. Just change your code the following:

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

Hope it helps you!



来源:https://stackoverflow.com/questions/38136660/generic-type-componentrefc-requires-1-type-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!