我在 html 中有这个跨度代码:
<span class="input-group-addon">{{currency_symbol}}</span>
我正在使用本地化。所以我使用 i18n 来表达 Angular 。当我得到 {{price_expression | } 时,我就正确地得到了它们。货币}}
我得到了正确的价格格式,但对于这个范围,我只需要货币符号,我怎样才能得到这个?谢谢!
最佳答案
您可以使用$locale服务
在你的 Controller 中:
$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;
但是要小心!
Each locale exists in its own file. These files are generated, with very little human intervention from the Google Closure Library i18n files.
At a minimum they must expose an 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.
( Source )
所以我建议这样:
$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM || '$';
关于javascript - 如何仅检索货币符号而不从 angularjs 货币过滤器格式化价格表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34927824/