What you will learn
Reuse element behavior with directives and pure display transformations with pipes.
- A directive adds behavior to an existing host element. Use host bindings and host listeners through the directive host metadata rather than querying unrelated DOM nodes.
- A pipe transforms a value for display. Pure pipes rerun when their input identity changes, so immutable updates work naturally.
- Do not hide expensive filtering inside a pipe for a very large list. A computed signal can make the transformation and dependency clearer.
- Built-in pipes such as DatePipe and CurrencyPipe are standalone imports and locale-aware.
How it works
1Element hosts directive
2Directive binds behavior
3Pipe transforms display value
4Template renders result
Expected result
The paragraph displays AR with a light-blue highlighted background.
Common mistakes
Do not mutate the input value inside a pipe. Do not create a directive that reaches across the page with document.querySelector. Import standalone directives and pipes where they are used.
