Performance: Structural vs attribute directives
MEDIUM IMPACT
This concept affects how Angular manipulates the DOM structure and attributes, impacting rendering speed and layout stability.
<div [ngStyle]="{'visibility': isVisible ? 'visible' : 'hidden'}">Content</div><div *ngIf="isVisible">Content</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Structural directive (*ngIf) | Adds/removes nodes | Triggers 1 reflow per toggle | Medium paint cost | [X] Bad for frequent toggles |
| Attribute directive ([ngStyle]) | No DOM changes | No reflows | Low paint cost | [OK] Good for toggling visibility |