mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs: clarify @for track expression scope to include properties and methods
(cherry picked from commit 2e0ca49f32)
This commit is contained in:
parent
161d98e7f2
commit
335d8c04dc
1 changed files with 4 additions and 4 deletions
|
|
@ -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 }}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue