货币换算 -- 用 angularjs 改变元素位置

Currency translation -- changing an elements place with angularjs

我在我的项目中使用 angular-translate,其中有 2 种语言(土耳其语和英语)。

在土耳其语中,商品的价格是这样写的:36₺, 但在美国,它就像:9 美元。

我不想对项目中的每个价格(有很多)使用 ng-if 来更改货币符号的位置。

那么有没有更短的方法来完成它?

像这样:

{{ lang == 'tr' ? '₺' + item.price : item.price + '$' }}

或者编写您自己的 Custom Filter 来解析您的货币。

考虑创建一个 custom filter that uses Number.prototype.toLocaleString()

console.log(Number(8).toLocaleString('en',{style: 'currency', currency: 'USD'}))
console.log(Number(8).toLocaleString('de',{style: 'currency', currency: 'EUR'}))