0

How could I get the key and the value too from an ng-options element, if I load the data from an object, not from an array?

HTML:

    <select ng-model="select" ng-options="value for (key, value) in brand"></select>
    <pre>{{select}}</pre>
<!-- {{select.key}}, {{select.value}} -->

Controller:

    $scope.brand = {
        'a': 'alpha',
        'b': 'bravo',
        'c': 'charlie',
        'd': 'delta'
    };

Fiddle

Thank in advance!

kree
  • 440
  • 1
  • 9
  • 26
  • It's ok, but I want to GET the key and the value, after the user selected from the menu... – kree Sep 05 '14 at 11:31
  • 1
    use `ng-options="key as value for (key, value) in brand"` as suggested. `key: {{select}}` and `value: {{brand[select]}}`. – AlwaysALearner Sep 05 '14 at 11:32
  • It's look like the best solution. Thank you! The updated fiddle: http://jsfiddle.net/Kreestian/mcy8yh7x/12/ – kree Sep 05 '14 at 11:51

0 Answers0