我創(chuàng)建了一個自定義組件,并將其放置在for循環(huán)中<div *ngFor="let view of views"> <customcomponent></customcomponent></div>其輸出將是:<customcomponent></customcomponent><customcomponent></customcomponent><customcomponent></customcomponent>我想知道當這些組件的數(shù)量可以變化時,如何使用@viewchild語法或任何其他方式來引用這些組件當組件可以被命名時<customcomponent #compID></customcomponent>然后,我可以如下引用它:@ViewChild('compID') test: CustomComponent如果不是這種情況,例如可能使用索引,我該如何引用呢?(此問題與先前已問過的其他問題無關(guān),使用ElementRef可以從下面列出的答案中看出)。此問題與訪問多個@ViewChild和使用列表查詢有關(guān)。
- 2 回答
- 0 關(guān)注
- 1410 瀏覽
添加回答
舉報
0/150
提交
取消