【发布时间】:2021-04-20 09:32:34
【问题描述】:
我想从一个数组动态创建组件。 #cmp1,#cmp2,#cmp3应该是动态的怎么实现的
<my-component #cmp1></my-component>
<my-component #cmp2></my-component>
<my-component #cmp3></my-component>
componentList: string[] = ['cmp1', 'cmp2', 'cmp3']
我必须在运行时根据字符串值动态获取这些组件
let reqiuredComponent = 'cmp2'
let captureComponent: MyComponent = @ViewChild(requiredComponent)
【问题讨论】:
-
为什么不使用 ViewChildren?你得到一个组件的 QueryList,你可以先得到,传递给数组....