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: