I'll make it pretty simple. I have:
<div ng-repeat="group in topLevelGroups">
....
<div ng-repeat="item in group.items | filter:itemFilter">
....
</div>
</div>
That's working all well and fine, but I want to display somewhere the total number of filter results across all "group"s.
To accomplish this, I moved the filter into the controller, like so:
<div ng-repeat="item in filterItems(group)">
// in controller:
$scope.filterItems = function(group) {
var ret = $filter('filter')(g.items, $scope.query);
g.filteredItemCount = ret.length
return ret
};
$scope.getTotalFiltered = function () {
return $scope.data.reduce(function (prev,cur) {
return prev + cur.filteredItemCount
}, 0)
}
So, essentially, piggyback a "filteredPostLength" property on to the group when the filter occurs, and use this to sum that property across all the groups to achieve total filtered results.
This is working just fine, but it feels rather hackish and I was wondering if there was a cleaner, more Angular way to accomplish this goal.
Any input is much appreciated, thanks!