Angular.filter('total')
HTML
<div ng-app="myApp" ng-controller="myController">
<table border="1">
<thead>
<tr>
<th>Order</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in datas">
<td>{{ $index + 1 }}</td>
<td>{{ data.price|currency }}</td>
</tr>
</tbody>
<tfoot>
<tr>
<!-- here is the magic -->
<th>{{ datas|total }} items</th>
<th>∑ {{ datas|total:'price'|currency }}</th>
</tr>
</tfoot>
</table>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp
.filter('total', function () {
return function (input, property) {
var i = input instanceof Array ? input.length : 0;
if (typeof property === 'undefined' || i === 0) {
return i;
} else if (isNaN(input[0][property])) {
throw 'filter total can count only numeric values';
} else {
var total = 0;
while (i--)
total += input[i][property];
return total;
}
};
})
.controller('myController', ['$scope',
function($scope) {
$scope.datas = [
{
price: 55
},
{
price: 72
},
{
price: 43
}
];
}]);