Twitter bootstrap 使用Angular2和Bootstrap 4表创建的附加列
这是我的HTML表格Twitter bootstrap 使用Angular2和Bootstrap 4表创建的附加列,twitter-bootstrap,angular,Twitter Bootstrap,Angular,这是我的HTML表格 <table class="table table-bordered"> <thead> <tr> <th *ngFor="let th of tableHeaders"> {{th}} <th> </tr> </thead>
<table class="table table-bordered">
<thead>
<tr>
<th *ngFor="let th of tableHeaders"> {{th}}
<th>
</tr>
</thead>
<tbody *ngIf="tableData.length">
<tr *ngFor="let tr of tableData">
<td *ngFor="let th of tableHeaders; let i = index">{{i}}
<td>
</tr>
</tbody>
</table>
{{th}
{{i}
附件是我的输出图像
值为iitsclear时,我只得到了9列,但生成的列为10列。你可以在城市后面看到一个空白栏
为什么呢?我怎样才能克服那个空白栏
尽管这是
中的一个失误,但我想推荐一种更好的方法来处理公共表组件,它可以在应用程序中使用,如下所示:
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 {}
从'@angular/core'导入{Component,NgModule}
从“@angular/platform browser”导入{BrowserModule}
@组成部分({
选择器:“我的应用程序”,
模板:`
你好{{name}
{{column.title}}
`,
})
导出类应用程序{
名称:字符串;
tableConfiguration:tableConfiguration;
构造函数(){
这个是.table配置={
列:新数组()
}
此文件名为.tableConfiguration.columns=
[{title:'First Name',columnSize:3},
{标题:“姓氏”,列大小:3},
{标题:'联系电话',列大小:2},
{标题:'性别',列大小:2},
{标题:'城市',列大小:2}];
this.name='Angular2动态表'
}
}
导出接口表配置{
列:数组;
}
导出接口列{
标题:字符串;
列大小:个数;
}
@NGD模块({
导入:[BrowserModule],
声明:[App],
引导:[应用程序]
})
导出类AppModule{}
注:
用于tableData和TableHeaders的json谢谢。我想出来了。我错过了th和td的结束标签。谢谢你的分数。我是为基于crud的应用程序写这篇文章的,所以我的列对于每个表都是动态的。我没有静态th。无论如何配置都是静态的。我的建议如上所述。但还是你的电话