Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: HTML select to use values from map

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.

like image 266
Archer Avatar asked Feb 07 '14 21:02

Archer


1 Answers

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

like image 110
Laurent Avatar answered Sep 27 '22 21:09

Laurent