AngularJS 使用参数创建过滤器
示例
默认情况下,过滤器只有一个参数:对其应用变量。但是您可以将更多参数传递给函数:
angular
.module('app', [])
.controller('MyController', function($scope) {
$scope.example = 0.098152;
})
.filter('percentage', function($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + ' %';
};
});现在,您可以给percentage过滤器一个精度:
<span ng-controller="MyController">{{ example | percentage: 2 }}</span>
=> "9.81 %"...但是其他参数是可选的,您仍然可以使用默认过滤器:
<span ng-controller="MyController">{{ example | percentage }}</span>
=> "9.8152 %"
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短