Counting Group Elements Using Angular Filter

Is it possible to use the "groupBy" angular filter ( https://github.com/a8m/angular-filter#groupby ) to count the elements in each group for use in the "icon" (of course, without using the aa function that performs "manual score" )

<div class="list-group" ng-repeat="(key, value) in directoryResult | groupBy: 'TableId'">
    <a href="#" class="list-group-item active">
        <span class="glyphicon glyphicon-transport"></span> {{convertTableid(key)}} <span class="badge">{{directoryResult.length}}</span>
    </a>
    <div class="list-group" ng-repeat="item in value">
        <a href="#" class="list-group-item">
            <span class="glyphicon glyphicon-transport"></span> {{item.Text}}
        </a>
    </div>
</div>
+4
source share
1 answer

If you do something like:

ng-repeat="(key, value) in directoryResult | groupBy: 'TableId' as result"

then there resultwill be a filtered variable. You can check the length of this number for the number of groups.

Update:

Here is a plunker with a groupBy filter.
http://plnkr.co/edit/8jB4wSRtKfVmEsTGZtfV?p=preview

, ( angular ) length. .

2:
:
http://plnkr.co/edit/iwUkIMjvevja7KyfTrFC?p=preview

angular -filter length, Object.keys

<div>Number of groups: {{numGroups(result) }} </div>

JS:

$scope.numGroups = function(input){
    return Object.keys(input).length;
}

3: : "", . , :

<div>Number of groups: {{numGroups(result[key]) }} </div>

4 , numGroups, :

<div>Number of groups: {{result[key].length}} </div>

, , . , .

+8
source

All Articles