2017-11-23 3 views
0

후 내가 예를 들어, 구성 요소에 대해 하나의 NG 후 모든 viewChildren에 액세스하고자 woul :액세스 NgFor

<component #item *ngFor="let item of items" [parameter1]="item.parameter1" [parameter2]="item.parameter2"></component> 

을 지금, 나는이 같은 ViewChildren 있습니다

@ViewChildren('item') item: QueryList<Item> 

하지만 내가 그를 console.log 때, 그것은 하나만 나타나고 모든 ngFor의 참조를 갖고 싶습니다

답변

1
조회 된 요소를 변경할 때 알림을받을 수있는 변화를 구독 할 수 있습니다

:

ngAfterViewInit() { 
    console.log(this.item.toArray()); 
    this.item.changes.subscribe(() => { 
    console.log(this.item.toArray()); 
    }); 
} 
1

시도해보십시오 .toArray, 작동 :

@ViewChildren('item') item; 

this.item.toArray()