The cleanest solution includes the ngRepeat as keyword ( https://docs.angularjs.org/api/ng/directive/ngRepeat ) and the custom filter total published by @aravinthan -k.
as keyword should be the last on the filter stack in ng-repeat . No matter what you do between different filters, the as alias will have the final result.total filter is easy to overwrite throughout your code.
Fiddle: http://jsfiddle.net/25g9hzzd/2/
HTML example:
<div ng-app="myapp"> <div ng-controller="Ctrl"> <h1>List</h1> <input type="text" ng-model="form.searchText"/> <ul> <li ng-repeat="item in list | filter: form.searchText as result"> {{item.title}} </li> <li>TOTAL: {{result | total:'number'}}</li> </ul> </div> </div>
Filter example (by @ aravinthan-k) and controller:
var app = angular.module('myapp', []); app.filter('total', function(){ return function(input, property) { var total = 0; angular.forEach(input, function(value, key) { total += parseFloat(value[property]) }); return total; } }); app.controller('Ctrl', function($scope){ $scope.form = { searchText: '' }; $scope.list = [ { title: 'A', number: 1 }, { title: 'AB', number: 2 }, { title: 'ABC', number: 3 }, { title: 'ABCD', number: 4 }, ]; });
tiblu source share