雖然是在<td>
一個小姐,我想建議的處理,這可以在應用程序中使用將是一個公用表組件一個更好的方式
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
<table class="table table-responsive">
<thead>
<tr>
<th *ngFor="let column of tableConfiguration.columns;"
class="col-md-{{column.columnSize}}">
{{column.title}}<th>
</tr>
</thead>
</table>
</div>
`,
})
export class App {
name:string;
tableConfiguration:TableConfiguration;
constructor() {
this.tableConfiguration ={
columns:new Array<Column>()
}
this.tableConfiguration.columns=
[{title: 'First Name',columnSize:3},
{title: 'Last Name',columnSize:3},
{title: 'Contact Number',columnSize:2},
{title: 'Gender',columnSize:2},
{title: 'City',columnSize:2}];
this.name = 'Angular2 Dynamic table'
}
}
export interface TableConfiguration{
columns:Array<Column>;
}
export interface Column{
title:string;
columnSize:number;
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
LIVE DEMO
備註:
- 變化,如你所願
- ColumnSize應增加至12,因爲它是默認的引導
- 使用此功能可以通過使用它CommonModule內跨應用程序包的選擇
您的JSON資料表和tableHeaders – Aravind
謝謝。我想到了。我錯過了th和td的/結束標記。 –