While I'm inside the ngFor directive, how is it possible to access the specific ngFor item via ElementRef? To make it clear:
<div>
<div class="color"></div>
<ul>
<li *ngFor="let item of numberList">
<div class="innercolor" #innercolor></div>
<p (click) = "onItemClick()" >{{item}}</p>
</li>
</ul>
</div>
In this code, #innercolor reference is not specific for any ngFor item so this is where the trouble begins. I've searched this, there's a solution with using QueryList in controller file, but i think this is too costy for handling a simple click event, querying all the list and iterating over and over again!
It would be great to give unique elementref to the elements of ngFor. Is there a way to make it? Or is there any other solution? I'm attaching the StackBlitz code below:
StackBlitz
I think this example is easily understandable. I would like to change the color of specific clicked list item but it only changes the first. When I click on second or third, I would like to change second or third's line color, but instead they all change the first line's color. Again, there's a solution with QueryList but I don't want to query all the list elements and pass the index to the controller, then iterate over query elements!
Any help would be great.