Angular · Senior · Question 15 of 75
Why are getters or methods in templates a common performance problem?
@for (p of filteredProducts(); track p.id) { <li>{{ p.name }}</li> }
filteredProducts() { return this.products.filter((p) => p.visible); }- ✓Correct answer: They run on every check and return new arrays, so the list is re-evaluated (and maybe re-rendered) each time
- 2Templates can't call methods with parameters
- 3Getters are evaluated only once and cache stale data
Explanation
Turn derived data into a computed() signal or a pure pipe: it is recalculated only when the inputs change. Profile with Angular DevTools to find components that check too often.