Member-only story

Building Better Angular Apps: Exploring Control Flow Syntax, Signals, and the New Build System 🔧✔️

Rebai Ahmed
3 min readNov 17, 2024

--

Introduction 📕:

Hello Angular folks and welcome to our new blog , today we will explore the new interesting features added by new Angular versions like control flow syntax, signals, and the new build system .

Control flow syntax 🔧:

Angular introduced the feature of built-in control flow for templates, a new declarative syntax of writing control flow, this eliminating the need to use *ngIf, *ngFor and ngSwitch

Code-Example:

// Before with *ngIf

<div *ngIf="isLoggedIn">
Welcome back, user!
</div>
// new syntax After with @if
<div> @if (isLoggedIn) { Welcome back, user! } </div>


-------------------------------------

// Before with *ngFor
<div *ngIf="user$ | async as user">
Hello, {{ user.name }}!
</div>
// new syntax After with @for
<ul>
@for (item of items; track item) {
<li> { {item} } </li>
}
</ul>

-------------------------------------
// Before with *ngSwitch
<div [ngSwitch]="userRole">
<span *ngSwitchCase="'admin'">Admin Access</span>
<span *ngSwitchCase="'user'">User Access</span>
<span *ngSwitchDefault>Guest Access</span>
</div>

// new syntax After with @switch

<div>
@switch (userRole) {
@case ('admin') {…

--

--

Rebai Ahmed
Rebai Ahmed

No responses yet