home / skills / hoangnguyen0403 / agent-skills-standard / directives-pipes
This skill helps you implement Angular Directives and Pure Pipes using standalone patterns for composition and reusable DOM behavior.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill directives-pipesReview the files below or copy the command above to add this skill to your agents.
---
name: Directives & Pipes
description: Composition patterns using HostDirectives and Pure Pipes.
metadata:
labels: [angular, directives, pipes, composition]
triggers:
files: ['**/*.directive.ts', '**/*.pipe.ts']
keywords: [hostDirectives, PipeTransform, pure]
---
# Directives & Pipes
## **Priority: P2 (MEDIUM)**
## Principles
- **Composition**: Use `hostDirectives` to compose behaviors onto components/directives without inheritance.
- **Pure Pipes**: Pipes must be `pure: true` (default). They cache results based on input reference.
- **Directive Logic**: Encapsulate reusable DOM manipulation or behavioral logic in Directives (e.g., `appFocusTrap`, `appTooltip`).
## Guidelines
- **Signal Inputs**: Directives also support signal inputs.
- **Standalone**: All Pipes and Directives must be standalone.
## References
- [Composition](references/composition.md)
This skill presents concise patterns for composing Angular behaviors using HostDirectives and for creating performant, reusable Pure Pipes. It focuses on clear separation of concerns: use directives for DOM/behavior logic and pipes for deterministic, cacheable transformations. The guidance emphasizes standalone, signal-aware implementations aligned with modern TypeScript and framework practices.
The skill explains how to attach reusable behaviors to components or directives via hostDirectives instead of inheritance, enabling composition without tight coupling. It also defines when to implement pipes as pure to leverage automatic memoization based on input references. Practical examples show encapsulating focus management, tooltips, or other DOM concerns in directives while keeping transformation logic in standalone pure pipes.
When should I make a pipe impure?
Use impure pipes only when the output depends on external state, time, or mutable inputs that do not change reference; note impure pipes run on every change detection tick and can hurt performance.
Can hostDirectives replace services?
HostDirectives are for composing UI behavior tied to the host element; use services for shared non-UI state, business logic, or cross-component coordination.