angular ngfor form 0 to variable code example
Example 1: how to loop a number in ngfor
//my.component.ts
counter(i: number) {
return new Array(i);
}
//my.component.html
<li *ngFor='let in of counter(5) ;let i = index'>{{i}}</li>
Example 2: ngfor index
<ul>
<li *ngFor="let item of items; let i = index" [attr.data-index]="i">
{{item}}
</li>
</ul>