Angular 4 vs. Angular 5

Angular 5 and 4 NgForOf and ngFor loops with Example

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!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Angular 5 and 4 NgForOf and ngFor loops with Example Angular 5 and 4 NgForOf and ngFor loops with Example Reviewed by Anil Singh on 8:14 PM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^