[Solved] Slides: Accessing a component created within an inner ngFor loop

Right, I found a way. I’d be interested to hear if it is the ‘Angular 2’ way :wink:

I used @ViewChildren

typescript class declaration:
@ViewChildren('CardSlider') cardSliders;

to access the index:

private onCardChanged(){
 // access  the array of card sliders by their _results array index: 0, 1, 2, 3 etc.
  let cardSlider = this.cardSliders._results[this.currentSuitIndex];
  console.log('Card changed', cardSlider.getActiveIndex());
}

This allows me to use #CardSlider as the (static) Template Variable; rather than a single unique ID it seems to create an array of components sharing the same ID, that can be referenced individually via the _results array.

1 Like