ngfor angular code example
Example 1: ngfor index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>
Example 2: ngfor get index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>
Example 3: ngFor
<div *ngFor='let [data] of [dataArray]; let i=index;'>
<h2> {{i}} {{data.title}} </h2>
<img src='{{data.image}}' />
</div>
Example 4: ngfor index
<ul>
<li *ngFor="let student of studentDetails; index as i;" [attr.data-index]="i">
{{student}}
</li>
</ul>
Example 5: ngfor
<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>