我想自動生成thead
和th
,基於模板td
:如何通過在Angular 2中檢查TD來將TH添加到TABLE中?
<Datatable>
<tr #lineSelected *ngFor="let subscription of results">
<td nameColumn="Nom">{{subscription.name}}</td>
<td nameColumn="Statut">{{subscription.status}}</td>
<td nameColumn="Origine">{{subscription.origin}}</td>
<td nameColumn="Date d'ajout">{{subscription.date}}</td>
</tr>
</Datatable>
現在:
<table>
<tbody>
<tr>
<td>name1</td>
<td>status1</td>
<td>origin1</td>
<td>date1</td>
</tr
<tr>
<td>name2</td>
<td>status2</td>
<td>origin2</td>
<td>date2</td>
</tr>
</tbody>
</table>
目標:
<table>
<thead>
<th>Nom</th>
<th>Statut</th>
<th>Origine</th>
<th>Date d'ajout</th>
</thead>
<tbody>
<tr>
<td>name1</td>
<td>status1</td>
<td>origin1</td>
<td>date1</td>
</tr
<tr>
<td>name2</td>
<td>status2</td>
<td>origin2</td>
<td>date2</td>
</tr>
</tbody>
</table>
這裏是我的component.ts
@Component({
selector: 'Datatable',
template: `
<table>
<ng-content></ng-content>
</table>
`,
styleUrls: ['./datatable.component.css']
})
export class DatatableComponent {
}
我該怎麼做?
你想在哪裏定義th內容? –
@MarkusKollers感謝您的回答,您可以檢查我的編輯嗎? – Steffi
我不知道你爲什麼要根據'td'自動生成'thead'和'th'。不知道默認情況下表中的列數? – Dimitri