【问题标题】:*ngFor for a data-range without a data-property in the component*ngFor 用于组件中没有数据属性的数据范围
【发布时间】:2017-04-25 03:39:07
【问题描述】:

在过去的 20 年中,是否有一种简单的方法可以使用 *ngFor 创建选择框的选项字段,例如从值 2016 到值 1996,组件中没有数据属性?

【问题讨论】:

    标签: angular range ngfor


    【解决方案1】:

    不,没有办法创建数组。

    AFAIK 可以在模板中创建的数组大小限制为 10 或 20(此限制最近也可能已被删除 - 不确定)。

    *ngFor="let x of [1,2,3...]"
    

    另见https://github.com/angular/angular/issues/8168

    改用类似的东西:

    *ngFor="let x of years"
    
    constructor() {
      this.years = []; 
      for(let i = 0; i < 20; ++i) { 
        this.years.push(2000 + i);
      } 
    } 
    

    【讨论】:

      猜你喜欢
      • 2017-12-11
      • 2012-11-10
      • 1970-01-01
      • 2021-08-08
      • 2018-10-16
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 2020-12-17
      相关资源
      最近更新 更多