-2

I'm starting to have problems binding data to a select using angular 1.2.18. CHecking with batarang ,I have those data in the scope:

ComuniNascitaList: 
[  { 
id: 
descrizione: Selezionare il comune di nascita
 } ,  { 
id: 6767
descrizione: Anghiari
 } ,  { 
id: 6780
descrizione: Arezzo
 } ,  { 
id:     6793
descrizione: Badia Tedalda
 } ,  { 
id: 6768
descrizione: Bibbiena
 } ,  { 
id: 6781
descrizione: Bucine
 } ,  { 
id: 6794
descrizione: Capolona
 } ,  { 
id: 6769
descrizione: Caprese Michelangelo
 } ,  { 
id: 6782
descrizione: Castel Focognano
 } ,  { 
id: 6795
descrizione: Castel San Niccolò
...

where id is the the key of the table this is how the binding is configured

ng-options="comune.id as comune.descrizione for comune in ComuniNascitaList" ng-model="ComuneNascitaSelezionato" 

but in the select list I find

option value="1">Anghiari

option value="2">Arezzo

option value="3">Badia Tedalda

option value="4">Bibbiena

option value="5">Bucine

Looks like is replacing the value of the id with a incremental value.

Seems to me that this is started from the update to 1.2.18 from 1.2.16, because before was working. Am I missing something?

Ravi Dhoriya ツ
  • 4,435
  • 8
  • 37
  • 48
Luca Morelli
  • 2,530
  • 3
  • 28
  • 45

1 Answers1

0

According to this

When you use ng-options, the values of option tags written out by ng-options will always be the index of the array item the option tag relates to.

In your case if you need to get the selected Comune's id you simple have to use {{ComuneNascitaSelezionato.id}} and don't worry about what the option tag contains but check only the model in your scope.

Community
  • 1
  • 1
Riccardo
  • 1,490
  • 2
  • 12
  • 22