Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
1 / 6
0

The Angular @switch Upgrades You Should Know About

DEV Community: angular·Brian Treese·3 days ago
#R3kZdPzT
#dev#case#badge#status#fullscreen#article
Reading 0:00
15s threshold

A ngular's @switch block has become a lot more useful recently. With exhaustive type checking, Angular can now catch missing template states when a TypeScript union or enum changes. And with grouped cases, we can remove duplicate markup when multiple states render the same UI. In this post, I'll show both improvements using a real-world example. The Problem: UI States Can Drift from Your Types Let's start with a common pattern. We have a support queue where each ticket has a status: There are four possible statuses, and we’re modeling them with a TypeScript union: type TicketStatus = | ' new ' | ' in-progress ' | ' resolved ' | ' closed ' ; interface Ticket { id : number ; title : string ; customer : string ; status : TicketStatus ; } Enter fullscreen mode Exit fullscreen mode Then, we have a signal containing a list of tickets: protected readonly tickets = signal < Ticket [] > ([ { id : 1024 , title : ' User cannot reset password ' , customer : ' Acme Corp ' , status : ' new ' , }, { id : 1025 , title…

Continue reading — create a free account

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

Read More