Reputation: 79
I have below function from which i was returning values, but now i want to add spaces after each commma.
Upvotes: 1
Views: 2901
Reputation: 1536
Try Using:
split with ,
and join with ,
var a = 'All,Where,When,Now,And';
var b = (a.split(',').join(', ')).trim();
console.log(b)
Upvotes: 1
Reputation: 361
Assuming you are using normal table to show your data and accounts is an array of objects ( since we dont have the exact structure of your data). In order to give space after comma you need to wrap you account name binding to span tag.
<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>
add below class at component level
.mr-5 {
"margin-right:5px"
}
Upvotes: 0
Reputation: 405
var string = 'hello,world';
string.replace(/,/g, ", ")
you can add using this replace function in your case:
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;
}
Upvotes: 0