I heard the rumor that the lifecycle methods of angular are going to be deprecated. Is this true? Can someone provide a valid source?
How can I replace them?
- ngOnChanges() -> Input-Signals
- ngOnInit() -> ?
- ngOnDestroy() -> ?
- ngAfterViewInit() -> ?
- ngAfterContentInit() -> ?
I heard the rumor that the lifecycle methods of angular are going to be deprecated. Is this true? Can someone provide a valid source?
How can I replace them?
- ngOnChanges() -> Input-Signals
- ngOnInit() -> ?
- ngOnDestroy() -> ?
- ngAfterViewInit() -> ?
- ngAfterContentInit() -> ?
1 Answer
Reset to default 2There is no deprecation is sight, but it is a reality that new APIs might be a better fit that the lifecycle hooks.
I recently wrote about it and did a talk on this.
ngOnInit
/ngOnChanges
can be replaced by signal based reactivity depending on the exact usecase (derivation via computed
/linkedSignal
/resource
) or effect()
/afterRenderEffect()
The "after" hooks, ngAfterViewInit
/ngAfterViewChecked
/ngAfterContentInit
/ngAfterContentChecked
can be replaced by afterNextRender()
/afterRender()
.
ngOnDestroy
has had an alternative for a bit longer with DestroyRef.onDestroy()
.