Similar to this related question, I want to group an array of objects, e.g., by team name
[
{name: 'Gene', team: 'team alpha'},
{name: 'George', team: 'team beta'},
{name: 'Steve', team: 'team gamma'},
{name: 'Paula', team: 'team beta'},
{name: 'Scruath of the 5th sector', team: 'team gamma'}
];
Unfortunately, the accepted answer using ng-repeat
with a groupBy
filter doesn't seem to work within an Angular Material expansion panel, which is what I'm trying to do:
I want multiple expansion panels, one per team, which, when expanded, show the involved players.
I tried
<mat-expansion-panel ng-repeat="(key, value) in players | groupBy: 'team'">
<mat-expansion-panel-header>
<mat-panel-title>{{ key }}</mat-panel-title>
</mat-expansion-panel-header>
<li ng-repeat="player in value">
{{player.name}}
</li>
</mat-expansion-panel>
However, ng-repeat
is not allowed inside the mat-expansion-panel
. *ngFor
is allowed but I don't know how to use it with the groupBy
filter. *ngFor="let player in players | groupBy: 'team'"
throws an error and I can't find any documentation.