I have a simple list of <div>
generated using *ngFor
directive, something like
<div *ngFor="let item of items() | async ; let i=index"
[ngClass]="getItemClass(i)"
(click)="itemClick(i)"</div>
As you see, the list is filled asynchronously any time the Observable returned by the method items()
emits. In my case such Observable is a ReplaySubject
, if this can be of any use to know. I then define the classes to be applied to each <div>
element using the method getItemClass
.
I want also to react to a click event on each item using the method itemClick(i: number)
.
Problem
Any time a div
element is clicked, i.e. any time the itemClick(i: number)
method is run, it seems that the entire list of <div>
s is rebuilt. I come to this conclusion observing that any time a div
element is clicked, also the items()
method is run.
Question
Is it possible to avoid rebuilding the list when one of the <div>
elements is clicked? I have already set changeDetection
to be OnPush but it does not seem to solve my problem.