Array filter within an object

1

1 I have an array of travel objects 2 each trip has an array of users (travelers) I need to create a filter to list travelers I created a filter for the destinations, but for the users it is not right. Anyone have any tips?

<script>
  var app = angular.module("viagem", []);

  app.controller("viagemController", function ($scope, $http) {

  $scope.viagens = [  
                     {  
                        "id":1,
                        "nomeTipoViagem":"Manutenção",
                        "destino":"Maranhâo",
                        "data":"2015-07-02",
                        "clientes":[  
                           {  
                              "nickname":"Cereais Comebem"
                           }
                        ],
                        "viajantes":[  
                           {  
                              "id_usuario":1,
                              "nome":"José Amaral"
                           },
                           {  
                              "id_usuario":2,
                              "nome":"Fernando Oliveira"
                           }
                        ],
                        "observacoes":null
                     }
                  ];
  });

</script>
  <body ng-app="viagem">
    {{viagens}}
    <table  ng-controller="viagemController" class="table table-bordered table-striped">
      <tbody>
        <tr>
          <th>Destino</th>
          <th>Viajantes</th>
        </tr>
        <tr>
          <td>
            <input type="text" class="form-control" ng-model="filtroDestino" ng-init="filtroDestino=''" />
          </td>

          <td>
            <input type="text" class="form-control" ng-model="filtroViajante" ng-init="filtroViajante=''" />
          </td>
        </tr>
        <tr ng-repeat="viagem in viagens  | filter:{destino:filtroDestino} | filter:{tipo:filtroTipo}">
          <td>{{viagem.destino}}</td>
          <td>
            <span ng-repeat="usuario in viagem.viajantes">{{usuario.nome}}                                                         <br />
            </span>
          </td>
        </tr>
      </tbody>
    </table>
  </body>

Plunker - Code

    
asked by anonymous 02.07.2015 / 15:42

1 answer

0

You just need to make a simple change to your code:

<td>
  <span ng-repeat="usuario in viagem.viajantes | filter:{nome:filtroViajante}">
      {{usuario.nome}} <br />
  </span>
</td>

Plunker - Code

    
17.07.2015 / 19:01