Angular *ngFor trackBy

1 · Valentin Knabel · July 19, 2022, midnight
When iterating over an array of objects in Angular, the change detection compares the references of the objects to detect changes. If the object reference now change too, like when updating local data from the network, Angular will discard the identity of all nested components within the ngFor and re-render the entire list. Even if the objects deeply equal, the change detection will still detect the change. To help our loop caching components and instead changing their inputs, we can add a track...