Iterating over an array that is a nested property with angularjs

80 Views Asked by At

I have this json:

    [{
   "id": 5,
   "dipendenti":    {
      "id": 2,
      "cognome": "panico",
      "dataCreazione": 1462100783589,
      "attivo": true,
      "dataModifica": 1462100783589,
      "nome": "ettore ",
      "anagrafica":       {
         "id": 2,
         "cap": 70054,
         "cellulare": "355454",
         "cf_partitaIva": "asfajiso",
         "dataCreazione": 1462100698288,
         "dataModifica": 1462923015482,
         "email": "ettopani",
         "facebook": "ettopani",
         "idcitta":          {
            "id": 1001,
            "nome": "Agliè"
         },
         "idprovincia":          {
            "id": 1,
            "nome": "Torino"
         },
         "indirizzo": "via viuli",
         "instagram": "ettopani",
         "nome": "ettore",
         "telefono": "457623"
      },
      "ruolis": [      {
         "id": 2,
         "descrizione": "Colui che si occupa delle vendite.",
         "nome": "Sales"
      }]
   },
   "password": "1234",
   "username": "deck80"
}]

I would like to print the property 'nome' of ruolis' array in this way (generating an html to be passed to a JS function):

nga.field('dipendenti.ruolis','template')
           .template('<span ng-repeat="ruolo in entry.values.dipendenti.ruolis track by $index">{{ruolo.nome}}</span>')

but it doesn't work.

Funny thing is that if I try with:

nga.field('dipendenti.ruolis','template')
               .template('<span ng-repeat="(key,value) in entry.values track by $index" class="label label-default">{{key}} {{value}}  ||</span>')

it displays this array:

[...lots of items...]
dipendenti.anagrafica.nome ettore ||dipendenti.anagrafica.telefono 457623 ||dipendenti.ruolis [{"id":2,"descrizione":"Colui che si occupa delle vendite.","nome":"Sales"}]

which shows indeed that the nested array is in property "dipendenti.ruolis".Where am I wrong?

Thank you all...

1

There are 1 best solutions below

0
On

(Posted on behalf of the OP).

Solution:

nga.field('dipendenti.ruolis')
               .template('<span ng-repeat="ruolo in value track by $index" class="label label-default">{{ruolo.nome}}</span>')
               .label('Ruolo')