[英]How render data from array in ng-container Angular 2?
我想將數據從數組呈現到HTML表中。 這是我的模型:
export class Section {
public id :number;
public name: string;
constructor(id: number, theName: string) {
this.id = id;
this.name = theName;
}
}
我將其導入並填寫到組件中:
import { Section } from "../models/registerSection.model";
數組聲明:
sectionList: Array<Section>;
數組填充在構造函數中:
this.sectionList = [new Section(1, "A"),
new Section(2, "B*"),
new Section(3, "C"),
new Section(4, "D")];
這就是我試圖在模板中呈現數據的方式:
<ng-container *ngFor='let data of Section'>
<tr>
<td colspan="7">{{data.name}}</td>
</tr>
</ng-container>
但是表是空的。 在DOM中,我看到以下內容:
<!--template bindings={
"ng-reflect-ng-for-of": null
}-->
我究竟做錯了什么? 在調試中,我可以看到該數組包含數據。
它應該是:
<ng-container *ngFor='let data of sectionList'>
現在,您正在嘗試遍歷Section
模型,而不是sectionList
該模型實例的sectionList
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.