【问题标题】:simple templete loop in Angular 2 [duplicate]Angular 2中的简单模板循环[重复]
【发布时间】:2018-04-10 09:32:04
【问题描述】:

我只想在html中创建一个简单的循环

比如

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

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

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

谁能帮我解决这个问题

【问题讨论】:

标签: angular angular2-template


【解决方案1】:

希望对你有帮助:)

组件

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 可能会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 2018-01-28
    • 1970-01-01
    • 2020-10-14
    • 2016-11-17
    • 1970-01-01
    • 2018-10-10
    相关资源
    最近更新 更多