Ho la seguente nel mio file HTML:AngularJS ng-modello converte oggetto stringa
<td style="width: 200px;">
<span ng-repeat="list in listGroups">
<label for="{{ list.description }}" />{{ list.description }}</label>
<input ng-model="$parent.listGroup" id="listGroup-{{ list.value }}" name="listGroups" value="{{ list }}" type="radio" />
</span>
</td>
I ListGroups contiene:
[
{
"description": "New by Territory",
"group": "product",
"type": "new"
},
{
"description": "New by Genre",
"group": "genre",
"type": "new"
},
{
"description": "Charts by Territory",
"group": "product",
"type": "chart"
},
{
"description": "Charts by Genre",
"group": "genre",
"type": "chart"
}
]
Quando clicco un pulsante di scelta della listGroup (set in ng -model) diventa, per esempio:
{"description":"New by Genre","group":"genre","type":"new"}
Quando guardo listgroup con typeof $scope.listGroup
, vedo che si tratta di un stringa ora!
Come tale, non posso accedere alle sue proprietà negli altri binding nel resto della pagina HTML.
In questo caso, voglio ng-show="listGroup.group == 'genre'"
Quello che sta succedendo qui e, cosa ancora più importante, come faccio a fargli fare quello che voglio fare, che è mantenere l'oggetto come un oggetto?
Grazie a tutti
Dave
Inoltre, non usare '$ parent', può darti problemi in futuro. – bmleite