javascript - 如何仅检索货币符号而不从 angularjs 货币过滤器格式化价格表达式

标签 javascript html angularjs

我在 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/

相关文章:

javascript - 获取跨域iframe的DOM内容

html - TW Bootstrap 缩略图背景颜色

javascript - 通过单击 AngularJs 中的按钮用输入文本框替换标签,反之亦然

javascript - 按钮倒计时启用

javascript - AngularJS 没有发生绑定(bind)

JavaScript 异步/等待

Javascript 文档.domain

javascript - 如何正确地将属性分配给函数作用域?

html - 如何使用 Bootstrap 4 对齐嵌套的表单行?

jQuery 双下拉导航问题