gpt4 book ai didi

javascript - 如何在 Angular View 中用空格 (' ' ) 替换下划线 (_)?

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:57 25 4
gpt4 key购买 nike

我在表格的标题中显示数组键,并且我的键中有下划线。我想在 html 表中用空格替换下划线。我不想在组件中执行此操作,因为我有其他要求。

<table>
<thead>
<tr>
<th *ngFor="let header of printFields">{{header}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let ab of printData">
<td *ngIf="ab.Bill_Number">{{ab.Bill_Number}}</td>
<td>.....</td>
<td>.....</td>
</tr>
</tbody>
</table>

最佳答案

如果只有一个实例你可以使用它,

 {{ header.replace('_', ' ') }} 

否则你必须使用过滤器

App.filter('strReplace', function () {
return function (input, from, to) {
input = input || '';
from = from || '';
to = to || '';
return input.replace(new RegExp(from, 'g'), to);
};
});

并像使用它一样

 {{ header | strReplace:'_':' ' }}

希望这有帮助:-)

关于javascript - 如何在 Angular View 中用空格 (' ' ) 替换下划线 (_)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49605911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com