NG.I · Angular 22 practice question

A developer needs a custom pipe to aggregate data from an array property within a component's view. Since the input array changes frequently but its contents might not change in a way Angular's standard change detection can track easily, which configuration must the pipe employ to ensure it recalculates upon every change detection cycle?

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({ name: 'dataAggregatorImpure', pure: false }) 
export class DataAggregatorPipe implements PipeTransform { transform(data: any[]): any { return data.reduce((acc, item) => acc + item.value, 0); } }
Choose one answer
Check answer and explanation

Correct answer: The pipe must be explicitly declared with `pure: false` in its `@Pipe` decorator.

Explanation

The pipe must be explicitly declared with `pure: false` in its `@Pipe` decorator, as this configuration tells Angular to bypass standard purity checks and re-execute the transformation function.

Common trap

Using `OnPush` on the component does not automatically force the pipe to run; the pipe's purity setting controls its execution frequency. Wrapping the input in a Signal is a modern Angular pattern but is not the direct mechanism described for making a pipe impure.

Source: Angular docs: Pipes — Detecting change within arrays or objects
Checked against the cited text on 2026-11-25.

Report an error in this question