Standalone Components
All components in Air Tracker are standalone components (not using NgModules).Creating a Standalone Component
Example fromflights-shell.component.ts:40-55:
Key Points
- No
standalone: trueneeded (defaults to true in Angular 20+) - Import all dependencies directly in the
importsarray - Import other standalone components, directives, and pipes
- Import Angular modules (like
MatGridListModule)
Generate Standalone Components
Component Structure
File Organization
Each component has its own directory:Component Class Structure
Follow this consistent structure (example fromflights-shell.component.ts:56-104):
Dependency Injection
Using inject() Function
Air Tracker uses the moderninject() function instead of constructor injection:
Access Modifiers for Injected Services
private readonly: Service not used in templateprotected readonly: Service used in template- Always use
readonlyfor injected dependencies
flights-shell.component.ts:57-62:
Signal Usage
Air Tracker extensively uses Angular signals for reactive state management.Input Signals
Use input signals instead of traditional@Input() decorators.
Example from polling-status.component.ts:15-20:
Setting Input Signals
In parent templates:Computed Signals
Use computed signals for derived state. Example frompolling-status.component.ts:38-60:
Writable Signals
Use writable signals for component state:Effects
Use effects for reactive side effects in the constructor. Example fromflights-shell.component.ts:72-100:
Effect Best Practices
- Place effects in the constructor
- Keep effects focused on a single concern
- Use local variables to track previous values for change detection
- Return early if signals haven’t changed
Service Integration
Store Pattern
Air Tracker uses a store pattern for state management. Example fromflights-store.service.ts:13-108:
Consuming Store in Components
Component Communication
Parent to Child - Input Signals
Child to Parent - Output Events
Shared State - Services
For complex state sharing, use services with signals:Lifecycle Hooks
Common Hooks
Using DestroyRef
Modern cleanup approach:Responsive Design
Viewport Service
Air Tracker includes aViewportService for responsive behavior.
Example from viewport.service.ts:8-42:
Using Viewport Service
Performance Best Practices
OnPush Change Detection
UseOnPush for better performance:
TrackBy Functions
Always usetrack in @for loops:
Avoid Memory Leaks
UseDestroyRef or takeUntilDestroyed() for subscriptions:
Testing Components
See the Testing Guide for detailed component testing patterns. Quick example:Next Steps
- Review code style guidelines
- Read the testing guide
- Check out the contributing guide
