javascript / beginner
Snippet
Repeating Content with @for
The @for block iterates over an array and renders a template block for each item. The 'track' expression is required for efficient DOM updates.
snippet.js
1
2
3
4
5
<ul>@for (task of tasks; track task.id) {<li>{{ task.name }}</li>}</ul>
angular
Breakdown
1
task of tasks
Declares a local variable 'task' for the current item in the 'tasks' array.
2
track task.id
A unique identifier for each item so Angular can optimize rendering when the list changes.