0

I am using Angular field groupBy https://github.com/a8m/angular-filter#groupby , it is working like a charm for a simple JSON file but here my problem

$scope.players = [
  {name: 'Gene', team: 'alpha'},
  {name: 'George', team: ['alpha','beta']},
];

I want to have :

  Group name: alpha
    * player: Gene
    * player: George
  Group name: beta
    * player: George

But with my code I have :

  Group name: alpha
    * player: Gene
  Group name: alpha,beta
    * player: George

My code is the same as the example

<ul>
  <li ng-repeat="(key, value) in players | groupBy: 'team'">
    Group name: {{ key }}
    <ul>
      <li ng-repeat="player in value">
        player: {{ player.name }}
      </li>
    </ul>
  </li>
</ul>

Any help would be really appreciated, Thank you very much

3
  • Looks like groupBy filter doesn't accept an array as input. Commented Jun 23, 2016 at 12:58
  • It's not the same as the example you have an array ['alpha','beta'] and a string 'alpha' Commented Jun 23, 2016 at 13:22
  • Yes but what would be the solution if a player plays at team alpha & beta at the same time ? Commented Jun 23, 2016 at 13:24

1 Answer 1

1

iterate over the team object inside player json and then pass it to the filter bcoz it does not accept array

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, but could you elaborate more please ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.