@if

Built-in control flow block for conditional rendering in templates.

Since Angular 17+ Spec ↗

Syntax

@if (condition) { ... } @else if (cond) { ... } @else { ... }

Parameters

NameTypeRequiredDescription
condition boolean No Expression determining which branch renders.

Returns

template block — Renders the matching branch only.

Examples

@if (user(); as u) {
  <p>Welcome {{ u.name }}</p>
} @else {
  <p>Please sign in</p>
}

Notes

The `@if` block replaces `*ngIf` and needs no structural directive import. Use `as` to alias the truthy value into a local variable. Supports any number of `@else if` branches followed by an optional `@else`.