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