简体   繁体   English

如何仅获取货币符号而无需从angularjs货币过滤器中格式化价格表达式

[英]How to retrieve only the currency symbol without formatting a price expression from angularjs currency filter

I have this span code in html: 我在html中有以下范围代码:

<span class="input-group-addon">{{currency_symbol}}</span>

I am using localisation. 我正在使用本地化。 So I am using i18n for angular. 所以我正在使用i18n进行角度测试。 I am getting them correctly when I get the {{price_expression | currency}} 当我收到{{price_expression | currency}} {{price_expression | currency}} i get the correct format with a price, but for this span I only need the symbol of the currency how can I get this? {{price_expression | currency}}我可以用价格获得正确的格式,但是在这个跨度内,我只需要货币符号,该如何获得? Thanks! 谢谢!

You can use the $locale service 您可以使用$ locale服务

In your controller: 在您的控制器中:

$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;

But be careful! 不过要小心!

Each locale exists in its own file. 每个语言环境都存在于其自己的文件中。 These files are generated, with very little human intervention from the Google Closure Library i18n files. 这些文件是生成的,而Google Closure Library i18n文件几乎不需要人工干预。

At a minimum they must expose an id. 至少他们必须公开一个ID。 In general they expose a load of other stuff such as number and date information. 通常,它们会暴露大量其他内容,例如数字和日期信息。 But Angular does not guarantee that this is the case. 但是Angular不能保证确实如此。

( Source ) 来源

So I suggest something like this: 所以我建议像这样:

$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM || '$';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM