@if
Built-in control flow block for conditional rendering in templates.
Syntax
@if (condition) { ... } @else if (cond) { ... } @else { ... } Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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`.