我試圖根據我得到的數據從服務器獲取響應後創建元素。是否有可能創建將在獲取新數據後更新DOM的組件?即加載後的角度2 DOM操作
<table>
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
<tbody>
...
</tbody>
</table>
我想在加載頁面後用angular2組件構建這樣的表。我試圖用對組件
@Component({
selector: 'thead',
template: `
<tr>
<th *ng-for="#th of tableHeaders">{{ th.name }}</th>
</tr>
`
})
export class TableHeader {
tableHeaders: Array<any>;
constructor() {
this.tableHeaders = [];
}
addHeader(header) {
this.tableHeaders.push(header)
}
}
和其他地方
...
this.http.get('/some/url')
.map(res: Response => res.json())
.subscribe(
(data: any) => {
for (var i = 0; i < data.tableColumns.length; i += 1) {
TableHeader.addHeader(data.tableColumns[i])
}
}
)
...
我在正確的方向白衣的是要做到這一點?