Question presented to candidate:
"What are pipes in Angular? Show me how you would use a built-in one, write a custom one, and explain what pure: false changes."
What a strong answer should cover:
- A pipe is a class with
@Pipe({ name })and atransform(value, ...args)method, used in templates as{{ value | name: arg }}to format or derive a value for display. - Built-ins from
@angular/common:date,currency,decimal,percent,uppercase,lowercase,titlecase,json,slice,keyvalue,async, and the i18n pipes; pipes chain left to right. - Pipes are standalone and must be imported into the component that uses them.
- Pure pipes (the default) re-run only when an input changes by reference or primitive value, so they are cheap; mutating an array or object does not re-run them.
- Impure pipes (
pure: false) run on every change detection pass of the view, so they see mutations but cost more;asyncis the famous impure built-in. - Compared to calling a method in the template, a pure pipe memoises on its inputs;
computed()is the signal-era alternative for component-level derived state.
Clarifying questions expected:
- "Is the data immutable, or do we mutate arrays in place?"
Code / implementation expected: Yes β a custom pipe with an argument, used in a template.