简体   繁体   中英

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/

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}} {{ test.approve | sumByColumn: 'amount' }} + {{a}} .

{{ test.approve | sumByColumn: 'amount' }} = 5 {{ test.approve | sumByColumn: 'amount' }} = 5 then $scope.a = 5 = 10 .

How can we achieve this ?

Like this:

{{ (test.approve | sumByColumn: 'amount') + a }}

https://jsfiddle.net/7b3q2q5p/9/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM