@for
Built-in control flow block for rendering lists with mandatory tracking.
Syntax
@for (item of items; track item.id) { ... } @empty { ... } Parameters
| Name | Type | Required | Description |
|---|---|---|---|
track | expression | No | Required key expression used to identify items across changes. |
Returns
template block — Renders the block per item; @empty when none.
Examples
@for (todo of todos(); track todo.id) {
<li>{{ $index + 1 }}. {{ todo.text }}</li>
} @empty {
<li>No todos yet</li>
}
Notes
`@for` replaces `*ngFor` and requires a `track` expression for efficient DOM
reuse (use a stable id, or `$index` for primitives). Implicit variables
include $index, $first, $last, $even, $odd, $count. The optional `@empty`
block renders when the collection is empty.