You could dynamically generate an array of however time you wanted to render <li>Something</li>
, and then do ngFor
over that collection. Also you could take use of index
of current element too.
Markup
<ul>
<li *ngFor="let item of createRange(5); let currentElementIndex=index+1">
{{currentElementIndex}} Something
</li>
</ul>
Code
createRange(number){
// var items: number[] = [];
// for(var i = 1; i <= number; i++){
// items.push(i);
// }
// return items;
return new Array(number);
}
Demo Here
Under the hood angular de-sugared this *ngFor
syntax to ng-template
version.
<ul>
<ng-template ngFor let-item [ngForOf]="createRange(5)" let-currentElementIndex="(index + 1)" [ngForTrackBy]="trackByFn">
{{currentElementIndex}} Something
</ng-template>
</ul>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…