angular/aio/content/blocks/core/if.md
Pawel Kozlowski 6b3f0bd0ea docs: control flow API reference (#52397)
Adds API reference for the new built-in control flow.

PR Close #52397
2023-10-27 12:56:51 -07:00

565 B

The @if block conditionally displays its content when its condition expression is truthy.

@syntax

@if (a > b) {
  {{a}} is greater than {{b}}
} @else if (b > a) {
  {{a}} is less than {{b}}
} @else {
  {{a}} is equal to {{b}}
}

@description

Content is added and removed from the DOM based on the evaluation of conditional expressions in the @if and @else blocks.

The built-in @if supports referencing of expression results to keep a solution for common coding patterns:

@if (users$ | async; as users) {
  {{ users.length }}
}