我有一件非常简单的事情。我想在我写的自定义过滤器中添加货币过滤器。
就是这样:
var app = angular.module('testapp', []);
app.controller('MainCtrl', function() {
this.people = [{
name: 'James',
bank: 5285
}, {
name: 'Mary',
bank: 849
}];
});
app.filter('richmeter', function() {
return function(bank) {
if (bank > 2500) {
return bank + ' [RICH]'
} else {
return bank;
}
}
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testapp">
<div ng-controller="MainCtrl as vm">
<div ng-repeat="people in vm.people | filter:richmeter">
{{people.name}} has {{people.bank | currency }}
</div>
</div>
</div>
&#13;
为什么这不起作用?我做错了什么?
谢谢。
答案 0 :(得分:0)
AngularJS currency
过滤器需要required amount parameter to be a number。在richmeter
过滤条件中,您似乎有条件地返回字符串,这意味着people.bank
将无法在currency
过滤器中按预期运行。