*ngFor 用于组件中没有数据-属性 的数据范围

*ngFor for a data-range without a data-property in the component

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

不,没有办法绕过创建数组。

据我所知,可以在模板中创建的数组的大小限制为 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);
  } 
}