为了账号安全,请及时绑定邮箱和手机立即绑定

使用@viewchild访问多个viewchildren

使用@viewchild访问多个viewchildren

哔哔one 2019-11-12 10:57:51
我创建了一个自定义组件,并将其放置在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和使用列表查询有关。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1340 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信