添加货币'自定义文件管理器中的过滤器 - Angular JS

时间:2017-03-29 15:01:39

标签: angularjs filter

我想在我的自定义过滤器中添加内置过滤器 - 货币。试图在角度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;
                }
            }
        })
})();

1 个答案:

答案 0 :(得分:0)

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

.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);