Why is calling a method in a template expression a performance problem?

Angular performance and SSR · Freshers and experienced

Model answer

Templates are checked often. A method call such as {{ getTotal() }} runs every time change detection checks that binding, even when nothing relevant changed, so an expensive method runs again and again.

Better options: compute the value once into a signal or computed, use a pure pipe, or store the result in a variable when the data changes. Simple getters of a signal, such as total(), are fine because signals cache computed results.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions