The NgForOf/ NgFor directive instantiates a template once per item from an iterable and the context for each instantiated template inherits from the outer context with the given loop variable set to the current item from the iterable.
The Selectors -
ü [ngFor]
ü [ngForOf]
Stayed Informed – Angular 5 and Angular 4 Documents
NgForOf with HTML Elements - The NgForOf directive is used with HTML elements as following.
<h2>User List - NgForOf and NgFor loops</h2>
<div>
<ul *ngFor ="let user of users | index as i">
<li>
{{i}} - {{user}}
</li>
</ul>
</div>
NgForOf with <ng-template> - The NgForOf directive is used with <ng-template> as following.
<h2>User List - NgForOf and NgFor loops</h2>
<div>
<!--With <ng-template> element -->
<ng-template ngFor let-user [ngForOf]="users" let-i="index">
<li>{{i}} - {{user}}</li>
</ng-template>
</div>
NgForOf with Async Pipe -
<h2>User List - NgForOf and NgFor loops with Async </h2>
<div>
<ul *ngFor ="let user of users | index as i; async">
<li>
{{i}} - {{user}}
</li>
</ul>
</div>
NgForOf with <ng-template> with Async -
<!-- User List - NgForOf and NgFor loops With <ng-template> element and Async -->
<div>
<ng-template ngFor let-user [ngForOf]="users | async" let-i="index">
<li>{{i}} - {{user}}</li>
</ng-template>
</div>
The Result looks like –
The Video example as following –
I hope you are enjoying with this post! Please share with you friends. Thank you!!