Skip to content

Instantly share code, notes, and snippets.

@maximLyakhov
Last active June 15, 2021 13:47
Show Gist options
  • Save maximLyakhov/0331d7c831b880f549b2785203c2e054 to your computer and use it in GitHub Desktop.
Save maximLyakhov/0331d7c831b880f549b2785203c2e054 to your computer and use it in GitHub Desktop.
angular recursive ngFor
<ul>
<ng-container *ngTemplateOutlet="recursiveList; context: { list: dataSource.data }"></ng-container>
</ul>
<ng-template #recursiveList let-list="list">
<li *ngFor="let item of list">
<div *ngIf="item">
{{ item | json }}
<span>
{{ item.name }}
</span>
<ul *ngIf="item.children && item.children.length > 0">
<ng-container *ngTemplateOutlet="recursiveList; context: { list: item.children }"></ng-container>
</ul>
</div>
</li>
</ng-template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment