Angular Migration Schematics
The Angular CLI provides automated migration schematics that handle mechanical refactors across major versions.
Common Migration Commands
# Update Angular packages
ng update @angular/cli @angular/core
# Migrate to standalone components
ng generate @angular/core:standalone
# Migrate to signal inputs
ng generate @angular/core:signal-input-migration
# Migrate to signal queries
ng generate @angular/core:signal-queries-migration
# Migrate to new control flow
ng generate @angular/core:control-flow-migration
# Migrate to inject()
ng generate @angular/core:inject-migration
Standalone Migration
# Convert NgModule-based app to standalone
ng generate @angular/core:standalone
This schematic:
- Converts bootstrap to bootstrapApplication()
- Removes AppModule
- Adds standalone: true to components
- Moves providers to app.config.ts
Signal Input Migration
# Convert @Input() to input()
ng generate @angular/core:signal-input-migration
Before:
@Input() title: string = '';
After:
title = input<string>('');
Incremental Adoption Patterns
Modern Angular features can be adopted incrementally without a risky big-bang rewrite.
Incremental Signal Adoption
// Step 1: Add signals alongside existing code
@Component({...})
export class MyComponent {
// Existing
@Input() title: string = '';
// New signal-based state
count = signal(0);
// Gradually migrate inputs to signals
// title = input<string>('');
}
Incremental Standalone Adoption
// Convert components one at a time
@Component({
selector: 'app-my-component',
standalone: true, // Add this
imports: [CommonModule], // Add explicit imports
template: `...`,
})
export class MyComponent {}
Strict Mode
// tsconfig.json
{
"compilerOptions": {
"strict": true,
"strictTemplates": true
}
}
Strict mode and template type checking surface breakage before users ever see it.
Migration Planning
- Audit — Identify deprecated APIs and patterns
- Update — Run ng update to latest version
- Migrate — Run schematics for mechanical changes
- Adopt — Incrementally adopt new features (signals, standalone, control flow)
- Verify — Run tests, lint, and build
- Deploy — Ship incrementally with feature flags
Quiz
1. What do Angular migration schematics do?
2. How do you adopt signals incrementally?
3. What does strict mode enable?
Flashcards
Question
What do migration schematics do?
Click to reveal answer
Answer
Automate mechanical refactors: standalone, signal inputs, control flow.
Question
How to adopt signals incrementally?
Click to reveal answer
Answer
Add signals alongside existing code. Migrate gradually.
Question
What does strict mode enable?
Click to reveal answer
Answer
Strict type checking + template type checking. Catches errors early.
Revision Notes
Key Takeaways
- 1. Migration schematics automate mechanical refactors
- 2. Signals and standalone can be adopted incrementally
- 3. Strict mode catches errors at compile time
- 4. Plan migrations: audit, update, migrate, adopt, verify, deploy
Interview Tips
- • Explain the Angular migration schematic system
- • Be ready to describe incremental adoption patterns
- • Mention strict mode for catching errors early
Cheat Sheet
Migration Strategies Cheat Sheet
Update packages:
ng update @angular/cli @angular/core
Common migrations:
- standalone:
ng generate @angular/core:standalone - signal inputs:
ng generate @angular/core:signal-input-migration - control flow:
ng generate @angular/core:control-flow-migration
Strict mode:
{ "compilerOptions": { "strict": true } }