【发布时间】:2017-03-31 01:05:53
【问题描述】:
我想迭代一个对象数组,但收到以下错误:
inline template:25:9 caused by: Cannot read property 'length' of null
以下是我的部分代码:
// Definition of the array
public columnsConfig: Array<ColumnConfig>;
其中ColumnConfig 是包含在数组中的所有实例的类。
// Constructor of the component
this.columnsConfig = new Array<ColumnConfig>();
// Function that builds the array to iterate
for(var columnName in _headers) {
let config = new ColumnConfig(columnName, _headers[columnName]);`
this.columnsConfig.push(config);`
}
模板:
<th *ngFor="let config of columnsConfig">
我在这里缺少什么?
【问题讨论】:
-
您发布的内容看起来不错。也许发布更多你的代码。
-
两件事:-尝试用一个测试 columnsConfig 存在的 ngIf* 来包装你的模板。 - 也许使用 |模板中的异步可能会有所帮助。