angular-patterns
Angular 21 development patterns for this project. Use when writing or reviewing Angular components, services, templates, or tests.
When & Why to Use This Skill
This Claude skill provides a comprehensive set of Angular 21 development patterns and best practices designed to streamline the creation, refactoring, and review of modern web applications. It emphasizes the use of signal-based reactivity, standalone components, and the latest control flow syntax to ensure high performance, maintainability, and WCAG AA accessibility compliance.
Use Cases
- Implementing Signal-Based Reactivity: Transition from traditional decorators to input(), output(), and computed() signals for more efficient and predictable state management.
- Modernizing Template Logic: Refactor legacy *ngIf and *ngFor directives into the new Angular control flow syntax (@if, @for) to enhance template readability and rendering speed.
- Standardizing Component Architecture: Enforce the use of ChangeDetectionStrategy.OnPush and standalone component defaults to optimize application performance and bundle size.
- Automating Accessibility Compliance: Apply WCAG AA standards and proper ARIA attributes during the design phase to ensure inclusive user experiences.
- Streamlining Unit Testing: Create robust test suites for standalone components using standardized TestBed configurations and signal-based input mocking.
| name | angular-patterns |
|---|---|
| description | Angular 21 development patterns for this project. Use when writing or reviewing Angular components, services, templates, or tests. |
Angular Patterns
Component Design
- Use
input(),output(),viewChild(),contentChild()signal-based functions instead of decorators - Do not add
standalone: true—it's the default in Angular 20+ - Use
ChangeDetectionStrategy.OnPushfor performance - Use Angular control flow syntax (
@if,@for,@switch) instead of*ngIf/*ngFor - Use
hostobject in decorator instead of@HostBinding/@HostListener - Use
class/stylebindings instead ofngClass/ngStyle - Use
providedIn: 'root'for singleton services
State Management
- Use
signal(),computed(), andeffect()for reactive state - Use
update()orset()on signals—nevermutate() - Use
toSignal()when interoperating with RxJS observables
Templates
- Keep templates simple; move logic to component classes
- No arrow functions in templates (not supported)
- No globals like
new Date()in templates - Use
@forwithtrackfor efficient list rendering
Styling
- Use Tailwind CSS with
@applyfor composite styles - Reference styles:
@reference '../../../styles.css'; - Support dark mode via
.dark:variants
Testing
- Use
TestBedwith standalone component imports - Set inputs via
fixture.componentRef.setInput('name', value) - Mock HTTP requests and dependencies
- Run with
ng test --include path/to/file.spec.ts
Accessibility
- Must pass AXE checks and meet WCAG AA standards
- Ensure proper focus management and ARIA attributes