Explain it simply
Structural: *ngFor, in plain language
*ngFor directive loops through an array to render a list of elements.
Problem → Why → Solution
The problem — why this concept matters
Tracking by array index can reuse the wrong row's DOM state after insertion or reordering.
A common mistake
One happy-path result does not prove the feature works; empty, loading, error, and cleanup behavior need explicit tests.
Core concept — understand how it works
List rendering creates an embedded view per iterable item and reuses DOM through identity tracking. Both legacy *ngFor and modern @for syntax are common; tracking by a stable unique ID preserves performance and local DOM state through updates and reordering. Derive filtered or sorted collections outside the template.
- input and state
- component and template
- rendered Angular UI
Explain the core concept and Angular data flow of Structural: *ngFor
Core syntax or pattern
<ul>
<li *ngFor="let user of users">
{{ user.name }} ({{ user.age }})
</li>
</ul>
// component.ts
export class MyComponent {
users = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
}List rendering creates an embedded view per iterable item and reuses DOM through identity tracking. Both legacy *ngFor and modern @for syntax are common; tracking by a stable unique ID preserves performance and local DOM state through updates and reordering. Derive filtered or sorted collections outside the template.
Read the code step by step
- input and state
<ul>*ngFor directive loops through an array to render a list of elements.
- component and template
export class MyComponent {List rendering creates an embedded view per iterable item and reuses DOM through identity tracking. Both legacy *ngFor and modern @for syntax are common; tracking by a stable unique ID preserves performance and local DOM state through updates and reordering. Derive filtered or sorted collections outside the template.
- rendered Angular UI
}Render an editable task list tracked by stable ID and verify focus and input values after add, delete, and reorder operations.
- input and state
- component and template
- rendered Angular UI
Success
Explain the core concept and Angular data flow of Structural: *ngFor
Failure
Tracking by array index can reuse the wrong row's DOM state after insertion or reordering.
*ngFor directive loops through an array to render a list of elements.
<ul>
<li *ngFor="let user of users">
{{ user.name }} ({{ user.age }})
</li>
</ul>
// component.ts
export class MyComponent {
users = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
}(A list showing the names and ages of 3 users will appear)Real-world usage
How to apply it in a real project
Render an editable task list tracked by stable ID and verify focus and input values after add, delete, and reorder operations.
Mini challenge
Build it yourself
Rebuild the Structural: *ngFor example without copying it. Add two normal states, one edge case, and one failure state, and write the expected UI and state transition before running it.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
<ul>
<li *ngFor="let user of users">
{{ user.name }} ({{ user.age }})
</li>
</ul>
// component.ts
export class MyComponent {
users = [
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 }
];
}Expected: Explain the core concept and Angular data flow of Structural: *ngFor
Show hint
Render an editable task list tracked by stable ID and verify focus and input values after add, delete, and reorder operations.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- input and state → component and template → rendered Angular UI
- List rendering creates an embedded view per iterable item and reuses DOM through identity tracking. Both legacy *ngFor and modern @for syntax are common; tracking by a stable unique ID preserves performance and local DOM state through updates and reordering. Derive filtered or sorted collections outside the template.
- Tracking by array index can reuse the wrong row's DOM state after insertion or reordering.
- Render an editable task list tracked by stable ID and verify focus and input values after add, delete, and reorder operations.
Angular — Templates — Angular