Angular 2 中的简单模板循环

simple templete loop in Angular 2

我只想在 html

中创建一个简单的循环

比如

for(int i = 1; i < n ; i++){
  //do something
}

我找到了可能的解决方案,但没有一个为我工作,这里是其中之一

<li *ngFor='#loop of counter(5) ;#i= index'>{{i}}</li>

谁能帮我解决这个问题

希望对您有所帮助 :)

组件

counter(number){
    // do something with the number passed
    let list: Array<number> = [1, 2, 3];
    return list;
  }

模板

<li *ngFor='let loop of counter(5);let i= index'>{{i}}</li>

最好从一些教程开始 this 可能会有帮助