【发布时间】:2017-03-03 02:16:47
【问题描述】:
我创建了一个自定义组件,我将它放在一个 for 循环中,例如
<div *ngFor="let view of views">
<customcomponent></customcomponent>
</div>
其输出将是:
<customcomponent></customcomponent>
<customcomponent></customcomponent>
<customcomponent></customcomponent>
我想知道当这些组件的数量可以变化时,如何使用@viewchild 语法或任何其他方式获得对这些组件的引用
当组件可以被命名时,例如
<customcomponent #compID></customcomponent>
然后我可以如下引用它:
@ViewChild('compID') test: CustomComponent
如果不是这种情况,例如可能使用索引,我如何引用它?
(这个问题与使用 ElementRef 无关,正如之前提出的其他问题一样,可以从下面列出的答案中看出)这个问题与访问多个 @ViewChild 和使用列表查询有关。
【问题讨论】:
标签: angular