【问题标题】:How to change currency position in Angular locale data?如何更改 Angular 语言环境数据中的货币头寸?
【发布时间】:2018-05-28 14:59:41
【问题描述】:
所以我们的客户是挪威人(nb,而不是nn),并且希望货币符号像nn 一样显示在右侧。 (不能将nb 更改为nn。)
我想知道是否可以修改 nb 的语言环境数据,但看起来我做不到。
我还在考虑猴子修补 Angular 内部使用的 getLocaleNumberFormat 方法,但不太确定如何使用 ES2015 导入来做到这一点。 ):
在我创建自己的管道之前还有其他聪明的解决方案吗?
【问题讨论】:
标签:
angular
internationalization
【解决方案1】:
你应该根据以下条件添加隐藏的 div
// use getLocaleNumberFormat, check currency symbol position
const currencyFormat = getLocaleNumberFormat(this.locale, NumberFormatStyle.Currency);
this.currencyPrefix = currencyFormat.startsWith('¤');
<div class="d-flex form-control-composed">
<div [hidden]="!currencyPrefix" class="position-absolute mt-2 ml-2">
{{currencyValue}}
</div>
<!--suppress HtmlFormInputWithoutLabel -->
<input type="text"
igxInput
[igxMask]="mask"
#fixedNumber
name="value"
[(ngModel)]="value"
[readOnly]="componentConfiguration?.readOnly"
[required]="componentConfiguration?.required"
(keyup)="validateFixedNumber(fixedNumber, $event)">
<div [hidden]="currencyPrefix" class="position-absolute mt-2 mr-2">
{{currencyValue}}
</div>
</div>