DEV Community

Matin Imam
Matin Imam

Posted on

πŸš€ Angular 19 Introduces @if, @for, @switch β€” Cleaner Templates Ahead!

If you're still using *ngIf, *ngFor, and *ngSwitch, Angular 19 just gave you a reason to upgrade your template game.

Angular now supports JavaScript-style control flow syntax directly in your templates:

@if (user) {
  <p>Hello, {{ user.name }}!</p>
} @else {
  <p>Please log in.</p>
}

@for (item of items; track item.id) {
  <li>{{ item.name }}</li>
} @empty {
  <li>No items found.</li>
}

@switch (status) {
  @case ('success') { <p>Success!</p> }
  @case ('error') { <p>Error!</p> }
  @default { <p>Unknown</p> }
}

Enter fullscreen mode Exit fullscreen mode

βœ… More readable
βœ… Less boilerplate
βœ… Built-in @empty and real @else blocks
βœ… IDE-friendly and intuitive

Want to see side-by-side comparisons with the old syntax?
πŸ‘‰ Read the full breakdown

Top comments (0)