Nahum
Nahum

Reputation: 7197

angular2 listing piped/filtered ngFor results

I got ng2 page with several nested *ngFor each with pipes I want to get the list of inner items in order to do action on all of them.

Something like this:

<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>

I want to list all d.item in a single list, and call a method on it.

Upvotes: 4

Views: 75

Answers (1)

Nahum
Nahum

Reputation: 7197

found a solution

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>

Upvotes: 2

Related Questions