Vivien Pipo Vivien Pipo - 1 year ago 63
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?

Answer Source

Try this:

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download