Templates

Pipes: pure, impure & async

Transforming values, the pure/impure performance trade-off, and the async pipe.

intermediate All levels

A pipe transforms a value for display via a transform method. Pure pipes (the default) recompute only when the input reference changes, so they are cheap and cached across change-detection cycles.

A pure pipe is a cached calculation stapled to its inputs; an impure pipe is a meter that re-reads on every tick whether or not anything changed.

Key concepts

1
An impure pipe (pure: false) runs on every cycle — necessary for things like filtering a mutable array, but a common performance trap. Prefer precomputing derived data in the component over an impure filter pipe.
impure pipepure: false
2
The async pipe subscribes to an observable/promise, returns the latest value, and unsubscribes automatically on destroy — the idiomatic way to render streams without leaks.
`async` pipeunsubscribes automaticallyasync
3
Pitfall: mutating an array in place will not trigger a pure pipe; return a new array. Interview follow-up: "why can filtering with an impure pipe hurt performance?" — it re-runs for every item on every CD tick.
Pitfall:Interview follow-up: