0

I am trying to show a list using ng-repeat but I couldn't figure out how to group it. This is my json:

 {
  "id": "1",
  "name": "Andre Nascimento",
  "client": "Lojas Mais"
},
{
  "id": "1",
  "name": "Andre Nascimento",
  "client": "Fe comercio"
},
{
  "id": "1",
  "name": "Andre Nascimento",
  "client": "Transtour"
},
{
  "id": "2",
  "name": "Carla Prata",
  "client": "Fe comercio"
},
{
  "id": "2",
  "name": "Carla Prata",
  "client": "Transtour"
}

I would like to getthe follow result

Andre Nascimento 
  *Lojas Mais
  *Fe comercio
  *Transtour

Carla Prata
  *Fe comercio
  *Transtour
Ugo Guazelli
  • 703
  • 3
  • 8
  • 19

1 Answers1

2

you can use angular.filter module as explained in this answer. Then you would have something like

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

this should do it.
here there is a fiddle

Community
  • 1
  • 1
Daniele Sassoli
  • 899
  • 12
  • 34