User_3535
User_3535

Reputation: 852

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' }} = 5 then $scope.a = 5 = 10 .

How can we achieve this ?

Upvotes: 0

Views: 77

Answers (1)

Dabbas
Dabbas

Reputation: 3230

Like this:

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

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

Upvotes: 3

Related Questions