docs: clarify @for track expression scope to include properties and methods

(cherry picked from commit 2e0ca49f32)
This commit is contained in:
Sam Severance 2026-05-04 19:29:04 -04:00 committed by Alex Rickabaugh
parent 161d98e7f2
commit 335d8c04dc

View file

@ -4,9 +4,9 @@ The `@for` block repeatedly renders content of a block for each item in a collec
```angular-html
@for (item of items; track item.name) {
<li>{{ item.name }}</li>
<li>{{ item.name }}</li>
} @empty {
<li>There are no items.</li>
<li>There are no items.</li>
}
```
@ -35,7 +35,7 @@ For collections that remain static , `track $index` provides a straightforward t
collections experiencing additions, deletions, or reordering, opt for a
unique property of each item as the tracking key.
Track expressions can only reference `$index`, the item, and fields from the component class. If the `let` segment of the `@for` block introduced an alias for `$index`, that alias may also be referenced.
Track expressions can only reference `$index`, the item, and properties and methods of the component class. If the `let` segment of the `@for` block introduced an alias for `$index`, that alias may also be referenced.
### `$index` and other contextual variables
@ -54,7 +54,7 @@ These variables are always available with these names, but can be aliased via a
```angular-html
@for (item of items; track item.id; let idx = $index, e = $even) {
Item #{{ idx }}: {{ item.name }}
Item #{{ idx }}: {{ item.name }}
}
```