【问题标题】:Add 'Currency' filter in custom filer - Angular JS在自定义过滤器中添加“货币”过滤器 - Angularjs
【发布时间】:2017-03-29 15:01:39
【问题描述】:

我想将内置过滤器 - 货币添加到我的自定义过滤器中。尝试在 Angular js 中做

 (function(angular) {
    'use strict';
    angular
        .module('testApp')
        .filter('amount', function() {
            return function(amount) {
                if (!amount) {
                    return 'Invalid Amount';
                } else {
                    //Here i want to add CURRENCY filter "| currency"
                    return amount;
                }
            }
        })
})();

【问题讨论】:

  • 返回“$”+金额;它不工作吗?
  • 我想格式化像 $5,493,274.86 这样的货币

标签: angularjs filter


【解决方案1】:

您可以使用数字过滤器。请尝试一下

.filter('amount', function($filter) {
            return function(amount) {
                if (!amount) {
                    return 'Invalid Amount';
                } else {
                    //Here i want to add CURRENCY filter "| currency"
                    var newAmount = $filter('number')(amount, 2);
                    return "$"+ newAmount;
                }
            }
  })

或者这样的

return $filter('currency')(amount, "$", 2);

【讨论】:

  • 是的,它运行良好。谢谢.. return $filter('currency')(amount, "$", 2);
猜你喜欢
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 2015-08-06
  • 2013-11-29
  • 1970-01-01
相关资源
最近更新 更多