我不能组件实例

问题描述 投票:0回答:0

在这种情况下,我需要使用带有动态组件的材质拖放模块, 我找到了一个解决方案并且它有效但现在我需要访问动态组件实例

components: CmpComponent[];

const childComponent = this.componentFactoryResolver.resolveComponentFactory(CustomComponent);
this.components.push(childComponent);


drop(event: CdkDragDrop<CmpComponent[]>) {
  moveItemInArray(this.components, event.previousIndex, event.currentIndex);
}

<div cdkDropList style="margin: 20px" (cdkDropListDropped)="drop($event)">
    <div cdkDrag *ngFor="let cmp of components">
        <app-cmp></app-cmp>
    </div>
</div>

不使用 createComponent 函数访问子组件实例应该怎么做?

javascript angular typescript angular-material factory
© www.soinside.com 2019 - 2024. All rights reserved.