【问题标题】:angularjs: how to convert values in table based on currency selection?angularjs:如何根据货币选择转换表中的值?
【发布时间】:2015-05-23 10:44:58
【问题描述】:

我有一张表,其中包含金额列。我在上面有一个货币下拉列表,其中包含世界上所有的货币,在选择任何货币时,我的金额应该通过汇率转换并显示在表格上。

我的方法面临几个挑战:

  1. 在这种情况下,objec 中的默认金额字段不应更改,我添加了假列以仅显示转换后的金额。对吗?

  2. 如何利用本地化和全球化。

如果有人遇到任何问题,我对此不太了解,请帮助我。

【问题讨论】:

    标签: angularjs angularjs-directive localization angularjs-ng-repeat globalization


    【解决方案1】:

    您可以使用过滤方法:

    .filter('currency', [function() {
        return function(amount, currency) {
            return amount.currency * currency.exchangeRate;
        }
    }]);
    

    对于你的模板

    <div ng-bind="amount | currency : currentSelectedCurrency"></div>
    

    这不会改变金额的值,只会改变它的显示方式。

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多