[英]How to add spaces after comma in Angular 8
我有下面的 function 我从中返回值,但现在我想在每个逗号后添加空格。
var string = 'hello,world';
string.replace(/,/g, ", ")
您可以在您的情况下使用此替换 function 添加:
getSchemaAccount(providerArr) {
const accountNameArr = [];
providerArr.forEach(provider => {
if (provider.asset_accounts.length > 0) {
provider.asset_accounts.forEach(account => {
const accountObj = { name: ' ', disabledAccount: false };
if (account.account_name && account.account_id !== this.allValue) {
accountObj.name = account.account_name.replace(/,/g, ", "); <---- add this
} else if (account.account_id === this.allValue) {
accountObj.name = this.allLabel.replace(/,/g, ", "); <---- add this
} else {
accountObj.name = account.account_id;
accountObj.disabledAccount = true;
}
accountNameArr.push(accountObj);
});
}
});
if(accountNameArr.length === 0) {
accountNameArr.push({ name: this.allLabel, disabledAccount: false });
}
return accountNameArr;
}
假设您使用普通表格来显示您的数据和帐户是一个对象数组(因为我们没有您数据的确切结构)。 为了在逗号后留出空间,您需要将帐户名绑定包装到 span 标签。
<tr *ngFor="let provider of providerData">
<td>{{provider.id}}</td>
<td *ngFor="let account of provider.accounts">
<span class="mr-5">{{account.account_name}} </span>
</td>
</tr>
在组件级别添加以下 class
.mr-5 {
"margin-right:5px"
}
尝试使用:
与 分开,
并与,
var a = 'All,Where,When,Now,And'; var b = (a.split(',').join(', ')).trim(); console.log(b)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.