I recently found this example in JSFiddle to select given option
in a select
element.
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 not create a global variable inside my controller like this:
$scope.selected;
And put the value of ng-model
of element select
with selected
and pass the value of ID that I want simply without doing the way you are doing? That is, passing the value of option
I want instead of a JSON object.
Are there other ways?