Performance: *ngFor for list rendering
MEDIUM IMPACT
*ngFor affects how many DOM elements are created and updated, impacting rendering speed and responsiveness when displaying lists.
<div *ngFor="let item of items; trackBy: trackById">{{item.name}}</div> trackById(index: number, item: any): any { return item.id; }
<div *ngFor="let item of items">{{item.name}}</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| *ngFor without trackBy | Destroys and recreates all nodes on list change | N reflows for N items | High paint cost due to full redraw | [X] Bad |
| *ngFor with trackBy | Reuses existing nodes, updates only changed items | Single or minimal reflows | Low paint cost, partial redraw | [OK] Good |