通用类型'ComponentRef< C>'需要1种类型的参数 [英] Generic type 'ComponentRef<C>' requires 1 type argument(s)
问题描述
无法移除ionic-2中的动态组件。在打字稿编译时说它是异常
Unable to remove dynamic components in ionic-2. It’s saying exception while typescript compile
通用类型'ComponentRef'需要1种类型的参数。
"Generic type 'ComponentRef' requires 1 type argument(s)".
此外,在不使用ionic2的情况下使用相同的代码。
非常感谢您的帮助。
先谢谢。
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++;
});
}
}
异常:TypeScript错误:...... / home / home.ts(9,11):Erro r
TS2314:通用类型'ComponentRef'需要1个类型的参数。
Exception: TypeScript error: ....../home/home.ts(9,11): Erro r TS2314: Generic type 'ComponentRef' requires 1 type argument(s).
推荐答案
ComponentRef
是泛型类型。只需更改以下代码:
ComponentRef
is a generic type. Just change your code the following:
class DynamicCmp {
_ref: ComponentRef<any>; <== add <any>
希望对您有帮助!
这篇关于通用类型'ComponentRef< C>'需要1种类型的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!