Menu

Angular signals and OnPush: a practical guide
📰

Angular signals and OnPush: a practical guide

DEV Community: angular·Mohammad Khalifeh·13 days ago
#Oi7RWLXt
#devtoangular#devto#dev#signal#angular
Long article (521 words) — no AI summary yet.
Reading 0:00
15s threshold

Angular signals change how a component tells the framework that something on screen is out of date. Combined with OnPush change detection, they let Angular skip almost every component on every tick and re-render only the ones whose data changed.

What a signal is

A signal is a value with a list of readers. When you call count() inside a template, Angular records that the template depends on count . When you call count.set(5) , Angular knows exactly which views need to update.

readonly count = signal ( 0 ) ; readonly doubled = computed ( ( ) => this . count ( ) * 2 ) ;

increment ( ) { this . count . update ( n => n + 1 ) ; }

Enter fullscreen mode

Exit fullscreen mode

computed is lazy and cached. It recalculates only when one of the signals it read has changed, and only when someone reads it.

Why OnPush matters

With the default strategy, Angular checks every component after every event, timer and HTTP response. On a small page that is fine.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.