0

I need a select with this

  { id: 111, shortName: 'RJ' },
  { id: 112, shortName: 'MG' },
  { id: 113, shortName: 'DF' }

I need to show the 'shortName' field on the selector, but the needs to be with the id value. This is what I have:

<select ng-model="model.StateId" ng-options="c.shortName for c in model.states"></select>

It shows the shortName correctly, but the option values are 0, 1, 2. How can I modify them with the id value on the array?

Matheus Lima
  • 2,103
  • 3
  • 31
  • 49

2 Answers2

3

The ng options should be like this:

ng-options="c.id as c.shortName for c in model.states">

The following is the plunker

http://plnkr.co/edit/kuKO5eZn10Cpe1DQEQPr?p=preview

madhured
  • 443
  • 2
  • 8
1

Use

<select ng-model="model.StateId" ng-options="c.id as c.shortName for c in model.states"></select>

That is ng-options = select as label for value in array

AngularJS select

kubuntu
  • 2,525
  • 1
  • 22
  • 24