javascript / intermediate
Snippet
Optimizing Performance with Pure Pipes
Pure pipes are only executed when their input arguments change by value or reference. This prevents unnecessary recalculations during Angular's change detection cycles, significantly improving performance for heavy tasks.
snippet.js
javascript
1
2
3
4
5
6
@Pipe({ name: 'square', pure: true, standalone: true })export class SquarePipe implements PipeTransform {transform(value: number): number {return value * value;}}
angular
Breakdown
1
pure: true
Tells Angular to cache the result and only re-run the pipe when inputs change.
2
transform(value: number)
The required method for implementing the data transformation logic of a pipe.