Use of trackby in *ngFor in Angular

Опубликовано: 19 Июнь 2026
на канале: Debasis Kar
108
3

Slackblitz link : https://stackblitz.com/edit/angular-i...
On the off chance that we need sooner or later to change the information in the assortment, for instance because of an API demand, we have an issue in light of the fact that Angular can't monitor things in the assortment and has no information on which things have been evacuated or included.

Accordingly, Angular requirements to evacuate all the DOM components that related with the information and make them once more. That implies a great deal of DOM controls particularly for a situation of a major assortment, and as we probably am aware, DOM controls are costly.

Note: when I'm stating "change the information" I'm alluding to supplant the assortment with new articles and not keeping a similar reference.

How about we see this in real life:

We can assist Angular with tracking which things included or evacuated by giving a trackBy work. The trackBy work takes the list and the present thing as contentions and necessities to restore the extraordinary identifier for this thing.