What’s new in Angular 16.2? Lifecycle methods

Angular keeps evolving at a steady pace, and Angular 16.2 brought a couple of interesting features to the table.

The first feature is an addition to the Signals API that was part of a specific RFC for Signal-based components. The new feature consists of two functions:

afterNextRender

A function that allows registering a callback to be invoked the next time the application finishes rendering. It is similar to the ngAfterViewInit lifecycle method but for signal-based components.

The main use-case for this new lifecycle is to initialize a third-party, non-Angular-friendly library to hook itself on the DOM after Angular generates it:

afterRender

A function very similar to the afterNextRender, with the difference that instead of running the registered callback just once, it will run it after every single render, similar to ngAfterContentChecked. This could be used to read something from the DOM when it changes, such as the height of an element:

Alain Chautard

Alain is a Google Developer Expert in Web Technologies, Angular, and Google Maps. His daily mission is to help development teams adopt Angular and build at scale with the framework. He has taught Angular on all six continents! A world traveler and photographer, Alain is also an international conference speaker, and a published author of several video courses.