Vivien Pipo Vivien Pipo - 4 months ago 15
AngularJS Question

Angular ng-option: iterate over a number array for displaying content of an other array but having index chosen in ng-model

I would like to have a dropdownlist that displays items of a string Array.
I also would like to have as ng-model the index of the selected item in the dropdownlist.

I know I did not give the best description , so I write What I would be able to do.


<select ng-model="chosenPropertyIndex"
ng-options="arrayProperties.PropertyNames[idx] for idx in [0,1,2,3,4,5]"


$scope.chosenPropertyIndex = 0;

$scope.arrayProperties = [
"Property A",
"Property B",
"Property C",
"Property D",
"Property E",
"Property F"

Do you see a way to do something like that please?


Try this:

<select ng-model="chosenPropertyIndex" ng-options="arrayProperties.indexOf(prop) as prop for prop in arrayProperties"></select>