html - 如何动态定义表格中列的宽度
问题描述
[Class.width]="header.width" 这不起作用。我怎样才能实现表格每一列的动态设置宽度。
app.component.html
<th class="name-center head-color " *ngFor="let header of tableHeader;let headIndex=index" [class.width]="header.width"
>{{header.value}}</th>
app.component.ts
this.tableHeader=[{"name":"sno","value":"S.No","width":"5%"},
{"name":"training","value":"Training","width":"35%"},
{"name":"skill","value":"Skill","width":"20%"},
{"name":"applicableProficiency","value":"Applicable proficiency","width":"20%"},
{"name":"trainingAction","value":"Training Action","width":"20%"}];
解决方案
您可以使用容器来保留对 tableHeader 项目的引用并相应地设置所需的宽度:
<table width="100%" border=1>
<tr>
<ng-container *ngFor="let header of tableHeader;let headIndex=index">
<th class="name-center head-color " [width]="header.width">{{header.value}}</th>
</ng-container>
</tr>
</table>
推荐阅读
- javascript - Lambda函数返回具有不同内存位置的函数?
- php - 从 PHP 中的嵌套数组中删除元素
- django - 如何覆盖默认的 Django 表单验证错误
- java - 从 Internet 获取 xml 文件时为 == null
- windows - ~t 返回空白而不是时间
- php - 如何在使用 symfony 保存缓存时修复“touch(): Utime failed: Operation not allowed”?
- c# - 无法隐式转换类型 system.collections.generic.IEnumerable
到字符串[] - php - Symfony 3 - 注意:反序列化():28 字节偏移量 11 处出错
- asp.net-core-mvc - 在 MVC Core 中使用现有数据库时出现 InvalidOperationException
- azure - HTTP 502:当一个函数与另一个计划函数保持温暖时