Angular v21 Development
Development guide for components, services, and directives based on Angular v21 modern patterns.
When to Use This Skill
- •Creating new components, services, or directives
- •Implementing signals-based state management
- •Implementing Reactive Forms
- •Refactoring existing code to Angular v21 patterns
- •Using inject() function for dependency injection
When NOT to use:
- •Styling only →
tailwindcss-v4-styling - •Page routing configuration →
analogjs-development - •UI/UX design application →
material-design-3-expressive
Core Principles
- •Standalone First: All components are standalone (do NOT write
standalone: truein decorator, it's default) - •OnPush Detection: Always set
changeDetection: ChangeDetectionStrategy.OnPush - •Signals-First: Prefer
signal(),computed(),effect() - •Modern DI: Use
inject()function instead of constructor injection - •Function-Based APIs: Use
input()/output()functions instead of@Input()/@Output()decorators - •Host Bindings in Decorator: Use
hostobject instead of@HostBinding/@HostListener - •Native Control Flow: Use
@if/@for/@switchinstead of*ngIf/*ngFor/*ngSwitch - •Class Binding: Use
[class]binding instead ofngClass - •Style Binding: Use
[style]binding instead ofngStyle
Implementation Guidelines
Component Creation
Patterns to apply when creating components:
- •Set
changeDetection: ChangeDetectionStrategy.OnPushin@Componentdecorator - •Define inputs/outputs with
input()/output()functions - •Calculate derived state with
computed() - •Use
@if/@for/@switchcontrol flow in templates
→ Details: Component Examples
Service Creation
Patterns to apply when creating services:
- •Use
@Injectable({ providedIn: 'root' })for singleton - •Inject dependencies with
inject()function - •Manage state with
signal(), expose withasReadonly() - •Define derived state with
computed() - •Update state with
set()orupdate()(do NOT usemutate())
→ Details: Signal Patterns
Reactive Forms
Patterns to apply when implementing forms:
- •Get
FormBuilderviainject() - •Use typed forms for type safety
- •Get values with
getRawValue() - •Add
ReactiveFormsModuleto imports
→ Details: Component Examples
Host Bindings
Host binding implementation patterns:
- •Do NOT use
@HostBinding/@HostListenerdecorators - •Use
hostobject in@Component/@Directivedecorator
→ Details: Component Examples
Image Optimization
Patterns to apply when displaying images:
- •Use
NgOptimizedImage(not for inline base64 images) - •Always specify
width/heightattributes - •Add
priorityattribute for above-the-fold images
→ Details: Component Examples
Workflow
- •Requirement Check: Define component responsibility and inputs/outputs
- •TDD Red Phase: Create test cases first
- •TDD Green Phase: Minimal implementation to pass tests
- •TDD Refactor Phase: Optimize code
- •Pattern Verification:
- •Is
changeDetection: ChangeDetectionStrategy.OnPushset? - •Are
input()/output()functions used? - •Is DI done with
inject()function? - •Are signals (
signal(),computed()) used?
- •Is
- •Accessibility: Check ARIA attributes, keyboard navigation
Related Skills
- •analogjs-development: Use together when creating page components (*.page.ts)
- •tailwindcss-v4-styling: When styling is needed
- •material-design-3-expressive: When applying UI/UX design patterns
Reference Documentation
For detailed patterns and code examples, see:
- •Signal Patterns - Detailed signal usage
- •Component Examples - Various component patterns