ngfor loop in angular code example
Example 1: angular ngfor index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>
Example 2: how to loop a number in ngfor
counter(i: number) {
return new Array(i);
}
<li *ngFor='let in of counter(5) ;let i = index'>{{i}}</li>
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
<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>