Performance: Component template basics
MEDIUM IMPACT
This affects the initial page load speed and rendering performance by controlling how much HTML and bindings Angular processes and renders.
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-good-template', template: ` <ul> <li *ngFor="let item of items()"> <strong>{{item.name}}</strong>: {{item.value}} </li> </ul> `, standalone: true }) export class GoodTemplateComponent { items = signal(Array(100).fill(0).map((_, i) => ({name: `Name ${i}`, value: i}))); }
import { Component } from '@angular/core'; @Component({ selector: 'app-bad-template', template: ` <div> <div *ngFor="let item of items"> <span>{{item.name}}</span> <span>{{item.value}}</span> <button (click)="doSomething(item)">Click</button> </div> </div> `, standalone: true }) export class BadTemplateComponent { items = Array(100).fill(0).map((_, i) => ({name: `Name ${i}`, value: i})); doSomething(item: any) { console.log(item); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Complex template with many bindings | High (100+ nodes) | High (100+ reflows) | High (many paints) | [X] Bad |
| Simplified template with fewer bindings | Moderate (100 nodes) | Low (single reflow) | Low (minimal paints) | [OK] Good |