I have a dropdown with a backing JSON like this:
$scope.tradestyles = [
{"id":"1","source":"Source One","name":"Name One"},
{"id":"2","source":"Source Two","name":"Name Two"}
]
This is the dropdown, using select2
, the model is the ID of the selected tradestyle:
<select id="tradestyle" ui-select2 ng-model="currentTradestyle" >
<option ng-repeat="tradestyle in tradestyles" value="{{tradestyle.id}}">
{{tradestyle.name}}
</option>
</select>
Next to it, I want to place a text field where the selected tradestyle's name is shown and can be edited.
<input type="text" ng-model="currentTradestyle" />
How do I change the model of the latter to point to the selected tradestyle's name rather than the ID? In other words, how do I traverse the scope object to point to the sibling name value of the selected ID value?