easyFrontend

Explain the new Control Flow (@if, @for, @switch) and how it compares to structural directives.

930 views
01

Understand the problem

Contrast the new block syntax in Angular 17 with *ngIf, *ngFor, and *ngSwitch.

control-flowdirectives
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Modern block control flow in Action
import { Component } from '@angular/core';

@Component({
  selector: 'app-flow-demo',
  standalone: true,
  template: '<h3>Users</h3>' +
    '@if (isAdmin) {' +
    '  <p class="badge">Admin Panel Mode</p>' +
    '} @else {' +
    '  <p class="badge">User Mode</p>' +
    '}' +
    '<ul>' +
    '  @for (user of users; track user.id; let idx = $index) {' +
    '    <li>#{{ idx }}: {{ user.name }}</li>' +
    '  } @empty {' +
    '    <li>No users registered.</li>' +
    '  }' +
    '</ul>'
})
export class FlowDemoComponent {
  isAdmin = false;
  users = [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' }
  ];
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.