Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 370
user2932411 Avatar asked Jul 01 '16 03:07

user2932411


1 Answers

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

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

Hope it helps you!

like image 113
yurzui Avatar answered Oct 17 '22 19:10

yurzui