[英]how to add a number with filter return value in angular.js
Hi I used this filter and getting desired output but in my case how to add a value to that filter. 嗨,我使用了此过滤器并获得了所需的输出,但是在我的情况下,如何为该过滤器添加一个值。
My filter: 我的过滤器:
angular
.module('Test', [])
.filter('sumByColumn', function () {
return function (collection, column) {
var total = 0;
collection.forEach(function (item) {
total += parseInt(item[column]);
});
return total;
};
});
jsfiddle : https://jsfiddle.net/7b3q2q5p/4/ jsfiddle: https ://jsfiddle.net/7b3q2q5p/4/
For example if i have a $scope.a = 5
then i have to add with the filter value in (fiddle example) like {{ test.approve | sumByColumn: 'amount' }} + {{a}}
例如,如果我有一个
$scope.a = 5
那么我必须在(小提琴示例)中添加过滤器值,例如{{ test.approve | sumByColumn: 'amount' }} + {{a}}
{{ test.approve | sumByColumn: 'amount' }} + {{a}}
. {{ test.approve | sumByColumn: 'amount' }} + {{a}}
。
{{ test.approve | sumByColumn: 'amount' }} = 5
{{ test.approve | sumByColumn: 'amount' }} = 5
then $scope.a = 5
= 10
. {{ test.approve | sumByColumn: 'amount' }} = 5
然后$scope.a = 5
= 10
。
How can we achieve this ? 我们怎样才能做到这一点?
Like this: 像这样:
{{ (test.approve | sumByColumn: 'amount') + a }}
https://jsfiddle.net/7b3q2q5p/9/ https://jsfiddle.net/7b3q2q5p/9/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.