0 day streak
javascript / beginner
Snippet

Displaying Lists with *ngFor

The *ngFor directive repeats an element for each item in a collection, such as an array of strings.

snippet.js
javascript
1
2
3
4
5
6
7
8
export class ListComponent {
tasks: string[] = ['Code', 'Test', 'Deploy'];
}
<!-- Template -->
<ul>
<li *ngFor="let task of tasks">{{ task }}</li>
</ul>
angular
Breakdown
1
tasks: string[] = [...];
An array property containing a list of strings to be displayed.
2
*ngFor="let task of tasks"
Iterates through the tasks array, assigning each item to the local variable 'task'.