【发布时间】:2017-04-25 03:39:07
【问题描述】:
在过去的 20 年中,是否有一种简单的方法可以使用 *ngFor 创建选择框的选项字段,例如从值 2016 到值 1996,组件中没有数据属性?
【问题讨论】:
在过去的 20 年中,是否有一种简单的方法可以使用 *ngFor 创建选择框的选项字段,例如从值 2016 到值 1996,组件中没有数据属性?
【问题讨论】:
不,没有办法创建数组。
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);
}
}
【讨论】: