This is an HTML example:
<select ng-model="inventory.condition"
ng-init="inventory.condition = con"
ng-options="con.name for con in conditions"
<option >-- choose condition --</option>
</select>
{{inventory.condition}}
In the AngularJS controller:
$scope.conditions = [
{"name":"New","id":101},
{"name":"Used","id":102},
{"name":"Like new","id":103},
{"name":"Not Working","id":104}
]
$scope.inventory.condition = {"name":"Used","id":102};
The SELECT population works fine, and if I select an item on the list it sets the ng-model correctly and the HTML displays the selected model correctly (I want to get the complete model selected, not just the "id" value), but I can't set the default value when building the list.
The idea is to receive a model (JavaScript object) that contains the default value (which really comes from an HTML request from a web service that is previously persisted in a database) and select the default item with the value from the model, and allow the user to change the same model by selecting a new item (which will be updated/persisted later).