1
I recently found that example in Jsfiddle to select particular option in one element select.
I noticed that it is selected as follows:
HTML:
<div class="listitem" ng-repeat="Choice in Person.Choices">
{{Choice.Name}}:
<select
ng-model="Choice.SelectedOption"
ng-options="choice.Name for choice in Choice.Options track by choice.ID"></select>
{{Choice.SelectedOption.ID}}
</div>
JSON:
{
"Name":"Dinner",
"Options":[{Name:"Fish",ID:1}, {Name:"Chicken",ID:2}, {Name:"Beef",ID:3}],
"SelectedOption":{Name:"Chicken",ID:2} // Neste trecho
}
Doubt:
I can’t create a global variable within my controller that way:
$scope.selected;
And put the value of ng-model of the element select with selected and pass the value of the ID I want simply without doing the way it’s doing? That is, passing the value of the option I want instead of a JSON object.
There are other ways?
I was doing exactly as you said @Ibotinelly, I’m using Angularjs 1.5, but when passing only the
oid(identifier) for the aspecter of the modelselectdid not change. But when I passed the whole object, with theoidand thedescricaocontained in theng-options, worked properly.$scope.objeto.oid = 1and$scope.objeto.descricao = "valor".– Giancarlo Abel Giulian