2025-11-06 18:03:05 +00:00
|
|
|
The `@if` block conditionally displays its content when its condition expression is truthy.
|
2023-11-01 01:02:22 +00:00
|
|
|
|
|
|
|
|
## Syntax
|
|
|
|
|
|
2024-07-22 15:37:24 +00:00
|
|
|
```angular-html
|
2023-11-01 01:02:22 +00:00
|
|
|
@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:
|
|
|
|
|
|
2024-07-22 15:37:24 +00:00
|
|
|
```angular-html
|
2023-11-01 01:02:22 +00:00
|
|
|
@if (users$ | async; as users) {
|
|
|
|
|
{{ users.length }}
|
|
|
|
|
}
|
|
|
|
|
```
|