【发布时间】:2019-10-10 21:15:23
【问题描述】:
如何定位嵌套循环下的特定项
<ul #parents *ngFor="let parent of parents">
<li #child *ngFor="let child of parents.childGroup"> {{child.name}} </li>
<ul>
Ts 文件
按照我的代码,我的目标是 parents[5].child[0] ,但它作为孩子工作 parents[0].child[0]
@ViewChildren('parents') parents : QueryList<ElementRef>
@ViewChildren('child') child: QueryList<ElementRef>
this.parents.forEach((item, index) => {
if (index === 5 ) {
(this.child.find( (item , index) => index === 0 ).nativeElement as HTMLElement).click();
}
});
每个父母都有自己的孩子,这里的目标是根据所有孩子索引计算的
如何解决这个问题?
【问题讨论】:
标签: angular angular6 angular7 ngfor