无法删除 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: Generic type 'ComponentRef' 需要 1 个类型参数。