我想要一个显示字符串数组项的下拉列表。 我还希望将下拉列表中所选项目的索引作为 ng-model。
我知道我没有给出最好的描述,所以我写了我能做什么。
HTML
<select ng-model="chosenPropertyIndex"
ng-options="arrayProperties.PropertyNames[idx] for idx in [0,1,2,3,4,5]"
></select>
Controller
$scope.chosenPropertyIndex = 0;
$scope.arrayProperties = [
"Property A",
"Property B",
"Property C",
"Property D",
"Property E",
"Property F"
];
请问您有没有办法做类似的事情?
最佳答案
试试这个:
<select ng-model="chosenPropertyIndex" ng-options="arrayProperties.indexOf(prop) as prop for prop in arrayProperties"></select>
关于javascript - Angular ng-选项 : iterate over a number array for displaying content of an other array but having index chosen in ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39386364/