0

There are other answers that deal with using ng-option with an object formatted like so:

 $scope.opts = [
  {value: 111, text: '1st' },
  {value: 222, text: '2nd' }
];

My question is, can it be done with an object formatted like this?

$scope.opts = [
  {'111': '1st'},
  {'222': '2nd'}
];

Trying it out doesn't work for me.

Any help?

To clarify:

I'd like the options to be like this <option value="111">1st</option, etc, where the browser shows 1st, and the model returns 111. Can this be done with an array of simplified objects?

Community
  • 1
  • 1
Mendel Kramer
  • 357
  • 3
  • 11

1 Answers1

1

No, the answer you point out does not say the same thing as you case. You have an array of objects having a single property with different names; the name of the single property is the key, the value is tha value.

The "object" syntax for the select is about an object, i.e. in your case it should be:

$scope.opts = {
    '111': '1st',
    '222': '2nd'
};

What you lose with this? No guaranteed iteration order.

Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90