【发布时间】:2016-07-30 04:45:13
【问题描述】:
我正在尝试在特定时间(角度 2.0.0-rc.4)迭代 for 循环。例如。 5次或10次..
home.component.html:
{{arr_length}} //printing 10 i.e. I have specified in home.component.ts
<tr *ngFor="let i of arr_length ; let ind = index">
<td>
//code goes here...
</td>
</tr>
但在 *ngFor 中会抛出错误:NgFor only supports binding to Iterables such as Arrays.
我是角度的新手。任何帮助,将不胜感激。
home.component.ts :
import { Component } from '@angular/core';
@Component({
selector: 'home',
templateUrl: '../templates/home.component.html',
directives: [],
providers: []
})
export class HomeComponent
{
arr_length: number;
constructor()
{
this.arr_length = 10;
}
}
【问题讨论】:
-
让我们看看您的组件代码。 home.component.ts
-
你的问题的答案就在错误的文本中。
-
@Casey:当我使用数组时,它工作正常但是如何在不使用任何数组的情况下迭代特定时间(例如 10 或 15)?
-
@Que : 我已经包含 home.component.ts 代码