我想要一个显示字符串Array的项目的下拉列表。
我还希望在下拉列表中将所选项目的索引作为ng模型。
我知道我没有给出最好的描述,所以我写了我能做的。
的HTML
<select ng-model="chosenPropertyIndex"
ng-options="arrayProperties.PropertyNames[idx] for idx in [0,1,2,3,4,5]"
></select>
控制者
$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>
http://jsfiddle.net/680x5grc/