【发布时间】:2020-09-15 00:45:40
【问题描述】:
我的代码如下
<table >
<thead >
<th *ngFor="let col of workData.columns;trackBy: trackByColumn;
let hindex=index;" [ngClass]="setWidth(col)" [index]="hindex">
</th>
</thead>
</table>
//TS File
setWidth(col){
if(col.field === 'First Name') {
col.width = '100px';
}
}
在上表中,我从 Http 调用中获取了列名 List 和列 Data 并基于它呈现表。 如何根据名称动态设置每列的宽度。
例如:
Column: First Name Width:100px
Column: Last Name Width:90px
Column: Address Width: 150px
我正在使用Angular 6。我尝试了javascript解决方案以及ngClass和ngStyle的角度。但我无法掌握如何为每列设置宽度。
【问题讨论】:
标签: html css angular html-table width