4

Have this HTML:

<select ng-model="group" ng-options="g.key for g in groups"></select>

Although $scope.groups is map {'a':'', 'b':'', 'c':''} I'd like select to display map keys: a,b,c

Currently it selects nothing. How to change ng-options?\

UPDATE 1

g for g in Object.keys(groups) does not work either.

1 Answer 1

11

You can use this syntax:

<select ng-model="group" ng-options="key for (key, g) in groups"></select>

You can check out the full documentation for the select directive, especially the ngOptions details: http://docs.angularjs.org/api/ng.directive:select

Sign up to request clarification or add additional context in comments.

1 Comment

It works, but inclorrectly. For some reason it dislpay unsorted items in select and if I try to select any item it just selects the last one and kinda freeze. I had to create another variable $scope.groupKeys = Object.keys($scope.groups) and use it. This way it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.