4

I have the following contoller in my app :

angular.module('myApp.controllers', []).
  controller('ClientesController', [ '$scope', '$rootScope', 'Clientes',
     function($scope, $rootScope, Clientes) {
        $rootScope.clientes;

        Clientes.query(function(response) {
          $rootScope.clientes = response;
  })
}]);

Which returns a JSON object with the following format :

 [{"idCliente":1,
   "nomeFantasia":"Flores",
   "razaoSocial":"Transportes Flores Ltda.",
   "contatosClientes": 
   [  
      {"idContatoCliente":1,
       "dddCelular":21,
       "email":"[email protected]"},
      {"idContatoCliente":2,
       "dddCelular":21,
       "email":"[email protected]"}
   ]
  }]

And a template which tries to parse the JSON with ng-repeat :

<tr ng-repeat="cliente in clientes | filter:searchText">
  <td>{{cliente.idCliente}}</td>
  <td>{{cliente.razaoSocial}}</td>
  <td>{{cliente.nomeFantasia}}</td>
  <td>{{cliente.contatosClientes.email}}</td>
  <td>
     <div class="right floated ui green icon buttons">
        <div class="ui button">Editar</i></div>
     </div>
  </td>
</tr>

The problem is that I can access the outer keys (idCliente,razaoSocial, etc) with the object.key sintaxe, but I can't access the inner keys (contatosClientes.email, for example) in the nested array.

I've tried many approaches and I am starting to think that is something wrong with my REST API, but before change all my backend code I would like to know if someone can help me with this issue.

Best regards, Antonio Belloni

1
  • 4
    contatosClientes is an array, you'll have to do ng-repeat for that too Commented Jul 6, 2015 at 19:10

1 Answer 1

5

contatosClientes is an array, you'll have to do ng-repeat for that too, for example:

<tr ng-repeat="cliente in clientes | filter:searchText">
  <td>{{cliente.idCliente}}</td>
  <td>{{cliente.razaoSocial}}</td>
  <td>{{cliente.nomeFantasia}}</td>
  <td ng-repeat="contato in cliente.contatosClientes>{{contato.email}}</td>
  <td>
     <div class="right floated ui green icon buttons">
        <div class="ui button">Editar</i></div>
     </div>
  </td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

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.