79637605

Date: 2025-05-25 11:23:51
Score: 0.5
Natty:
Report link

Another more modern approach than using the ngFor directive:

<app-parent>
    @for (child of children; track child.id; let idx = $index) { 
        <app-child [index]="idx" [data]="child" />
    }
</app-parent>

Assuming that children is a collection of data group for each app-child component you want to render and the app-child component has input properties to receive this data.

The @for operator was recently added to Angular in version 17. I think this is a way more intuitive approach for repeatedly rendering elements on the page especially for people coming from languages such as Python or C#. More on the @for block here

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @for
  • Low reputation (0.5):
Posted by: Anton Kovachev