<div ng-controller="ExampleController">
<form name="myForm">
<label for="mySelect">Make a choice:</label>
<select name="mySelect" id="mySelect"
ng-options="option.name for option in data.availableOptions track by option.id"
custom-attribute = "{{optionNumber}}+ Value"
ng-model="data.selectedOption"></select>
</form>
</div>
$scope.data = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
]
在此示例中,我想根据选项号将相应的选项号传递给custom-attribute。例如:对于option1,它将是“1 Value”,对于option2,它将是“2 Value”。
虽然,我可以使用ng-repeat代替ng-options(在$ index的帮助下)来实现它。我想用ng-options做到这一点。