2017-04-27 88 views
4

嗨,大家好我NG2页面与几个嵌套* ngFor每个管我想以做所有这些行动内的项目列表,angular2上市管道/过滤ngFor导致

这样的事情:

<div *ngFor="let a of b | x |y | z"> 
    <div *ngFor="let c of a | x |y | z"> 
    <div *ngFor="let d of c"> 
     <div [service]="(d.item|async)"></div> 
    </div> 
    </div> 
</div> 

我想列出所有d.item在一个列表中并调用它的方法。

回答

2

找到了解决办法

export class component { 
 

 
    @ViewChildren('myVar') createdItems; 
 

 
    showChildren() { 
 
    console.log(this.createdItems.toArray().length); 
 
    } 
 
    }
<div *ngFor="let a of b | x |y | z"> 
 
    <div *ngFor="let c of a | x |y | z"> 
 
    <div *ngFor="let d of c"> 
 
     <my-component #myVar [service]="(d.item|async)"></div> 
 
    </div> 
 
    </div> 
 
</div>

+0

你知道什么是'createdItems'的类型? – baryo

+0

@baryo 它的一个https://angular.io/docs/js/latest/api/core/index/QueryList-class.html 与结果是内循环的我的组件 – Nahum

+0

酷感谢类型。可能想要用它更新您的示例。 – baryo