Reputation: 597
I woul like to access all the viewChildren after one ng for to a component, for example:
<component #item *ngFor="let item of items" [parameter1]="item.parameter1" [parameter2]="item.parameter2"></component>
Now, i have a ViewChildren like this:
@ViewChildren('item') item: QueryList<Item>
but when i console.log him, it only appears one and i would like to have the reference of every of the ngFor
Upvotes: 3
Views: 2739
Reputation: 21387
try this .toArray, it works :
@ViewChildren('item') item;
this.item.toArray()
Upvotes: 2
Reputation: 657957
You can subscribe to changes to get notified when the queried elements change:
ngAfterViewInit() {
console.log(this.item.toArray());
this.item.changes.subscribe(() => {
console.log(this.item.toArray());
});
}
Upvotes: 1