Overview
Lifecycle hooks provide visibility into key moments in a component or directive’s lifecycle, from creation to destruction. Angular calls these hook methods in a specific sequence.Lifecycle Sequence
- Constructor - Class instantiation (not a hook)
- OnChanges - Input property changes
- OnInit - Initialization after first change detection
- DoCheck - Custom change detection
- AfterContentInit - Content projection initialized (once)
- AfterContentChecked - Content projection checked
- AfterViewInit - View initialized (once)
- AfterViewChecked - View checked
- OnDestroy - Cleanup before destruction
OnChanges
Interface
Description
Called when any data-bound input property changes. Receives aSimpleChanges object containing current and previous values.
Parameters
SimpleChanges
Object containing changed properties with their current and previous values.
Example
user-profile.component.ts
ngOnChanges is called before ngOnInit and whenever input properties change. It’s not called for internal state changes.OnInit
Interface
Description
Called once after the firstngOnChanges. Used for component initialization logic.
Example
data-list.component.ts
DoCheck
Interface
Description
Called during every change detection cycle. Use for custom change detection logic.Example
custom-check.component.ts
AfterContentInit
Interface
Description
Called once after Angular projects external content into the component’s view (content children).Example
tab-container.component.ts
AfterContentChecked
Interface
Description
Called after Angular checks the content projected into the component.Example
content-wrapper.component.ts
AfterViewInit
Interface
Description
Called once after Angular initializes the component’s views and child views.Example
chart.component.ts
View children are guaranteed to be initialized in
ngAfterViewInit. Don’t try to access them in ngOnInit.AfterViewChecked
Interface
Description
Called after Angular checks the component’s views and child views.Example
scroll-monitor.component.ts
OnDestroy
Interface
Description
Called just before Angular destroys the component or directive. Used for cleanup logic.Example
timer.component.ts
Complete Lifecycle Example
full-lifecycle.component.ts
Hook Call Frequency
Best Practices
Signal-Based Alternative
With Angular signals, many lifecycle hooks can be replaced:signal-component.ts
Related APIs
- @Component - Define components
- @Directive - Define directives
- SimpleChanges - Input change information
- effect() - Signal-based reactive effects
See Also
Lifecycle Guide
Component lifecycle guide
Change Detection
How change detection works
Queries
Query child components
Signals
Modern reactive patterns
