Within my template, I use *ngFor
<div #listofbars *ngFor="let points of pointsNormalized; let i =index" [attr.data-index]="i">
<div *ngIf="i < 10" class="ranking d-flex align-items-center" [ngClass]="setBarClass(i)" [attr.id]="'bar-id-' + i">
And then I try to access the 0th child element like so:
@ViewChildren("listofbars") list_container: QueryList<ElementRef>;
if (this.list_container) {
if (this.list_container.toArray()[0]) {
console.log(this.list_container.toArray()[0].nativeElement);
}
}
However, it appears, when I check the Chrome console, that the element is actually not contained within the html source. I'm trying to use the element reference to build an animation, but it does not work when I access elements within ngFor (it has worked when I tried it on elements outside of ngFor). What's the correct to get a native element reference within the ngFor directive?