【发布时间】:2020-12-08 16:08:47
【问题描述】:
我在 viewContainerRef 中添加了动态组件 (ChildComponent.ts)。如果我使用索引来获取子组件 (viewContainerRef.get(0)),我可以像这样从 viewContainerRef 获取子组件数量viewContainerRef.get(0),它会返回 ViewRef 但我需要子组件如何执行此操作。
例子:
@ViewChild("cards_holder", { read: ViewContainerRef }) cards_holder: ViewContainerRef;
const componentFactory = this.resolver.resolveComponentFactory( SimpleCardComponent);
const componentRef = this.cards_holder.createComponent(componentFactory);
for (let index = 0; index < this.cards_holder.length; index++) {
console.log(this.cards_holder.get(index)) //It's Return ViewRef but i need SimpleCardComponent
}
谢谢。 Sabish.M
【问题讨论】:
标签: angular angular9 angular-dynamic-components