Adopting Angular Control Flow in Standalone Components
Use Angular's @if/@for/@switch control flow in new standalone components, but verify your @angular/core version before retiring *ngIf and *ngFor.
23 Aug 2026, 05:15 UTC

You generate a new standalone component and reach for *ngIf and *ngFor by habit. That still works in many Angular projects, but it is no longer the default choice for new feature code. Angular’s control flow syntax—@if, @for, and @switch—is built into standalone components and does not require importing NgIf or NgForOf from CommonModule.
The practical takeaway: adopt control flow in new standalone components, keep structural directives in legacy NgModule code until you migrate, and confirm your installed @angular/core version supports the syntax before making it a team standard.
Check your Angular version first
Control flow landed in the Angular 17 release line and was refined in later minor versions. Exact support depends on your installed @angular/core minor version, so treat the Angular release notes for that version as the reference.
Run ng version in a terminal at the project root. No special permissions are required beyond read access to the workspace. Check the Angular CLI and @angular/core versions. If your major version is below 17, control flow is not available. If you are on 17 or later, confirm the minor version against the release notes before standardizing the syntax.
Worked example: a user list with @for and @if
Generate a standalone component from the project root:
ng generate component user-list --standalone
This command requires write access to the workspace. Replace user-list with your component placeholder if needed. Expected result: a new component class, template, and stylesheet are created. A risk is a name collision if a component with that name already exists, and a template parse failure if the project’s Angular version predates control flow.
In the component class, import AsyncPipe from @angular/common. Control flow itself needs no CommonModule import, but the async pipe still does:
import { Component } from '@angular/core';
import { AsyncPipe } from '@angular/common';
@Component({
selector: 'app-user-list',
standalone: true,
imports: [AsyncPipe],
templateUrl: './user-list.component.html',
})
export class UserListComponent {
users$ = this.userService.getUsers();
constructor(private userService: UserService) {}
}
Template:
@if (users$ | async as users) {
Users
@for (user of users; track user.id) {
- {{ user.name }}
} @empty {
- No users found.
}
} @else {
Loading users...
}
The as users alias gives the template a local variable for the resolved array. Inside the @if block, TypeScript can narrow users to the resolved type rather than the observable wrapper. The track user.id expression tells Angular which items changed, which avoids rebuilding the entire list when only one entry is added or removed. The @empty block replaces the separate empty-state check you would otherwise write with another structural directive.
Comparison and lifecycle caution
| Concern | *ngIf / *ngFor | @if / @for / @switch |
|---|---|---|
| CommonModule import | Required in NgModule contexts | Not required for control flow in standalone components |
| Type narrowing | Limited | Narrows types inside @if blocks |
| Item tracking | trackBy on the directive | track expression directly in @for |
| Empty state | Separate *ngIf check | @empty block inside @for |
Do not place *ngIf and @if on the same element expecting identical lifecycle semantics. Control flow can create or destroy embedded views at different times, which affects animations, element focus, and child component initialization.
Limitations and how to verify
@forwithout a track expression on large lists can degrade change detection, similar tongForwithouttrackBy.- Existing modules that import
CommonModulecontinue to work. Do not rewrite stable legacy code solely to change syntax. - New standalone components should not assume
NgIforNgForOfare available unless explicitly imported, though control flow usually makes those imports unnecessary.
Verify by running ng build after adding a control-flow template and inspecting template type errors inside @if branches. Search the repository for *ngIf and *ngFor in components under your new feature folder to decide whether to replace or retain them.
Action
Make control flow the default for new standalone feature components in your next sprint. Add an @angular/core version check to your component template checklist. Leave legacy NgModule templates untouched until a planned migration, and treat Angular 17 or later as the baseline for this convention.