-1

I'm trying to set the default option in a select element in an Angular app. Below is what I've tried, but my select box is empty:

<select ng-init="selectedMax = game.player.max_points"
        ng-options="option for option in game.maxOptions"
        ng-model="selectedMax"
        ng-change="changeMax()"></select>

Basically I want my default option to be game.player.max_points which is a value set by my controller on initiation.

Alex Netkachov
  • 13,172
  • 6
  • 53
  • 85
MattDionis
  • 3,534
  • 10
  • 51
  • 105
  • http://stackoverflow.com/questions/17968760/how-to-set-a-selected-option-of-a-dropdown-list-control-using-angular-js – Seano666 Jul 28 '15 at 22:34

2 Answers2

0

Select one of the available options:

<select ng-init="selectedMax = game.maxOptions[0]" ng-options="option for option in game.maxOptions" ng-model="selectedMax" ng-change="changeMax()"></select>

or try setting it in your controller: http://codepen.io/anon/pen/PqxmvG

Tzach Ovadia
  • 1,278
  • 9
  • 18
0

I think you have to tell to the ng-options directive what field to use from the options array. Something like this:

<select ng-init="selectedMax = game.player.max_points" 
        ng-options="option.fieldName for option in game.maxOptions"
        ng-model="selectedMax" 
        ng-change="changeMax()">
</select>
Snappawapa
  • 1,697
  • 3
  • 20
  • 42
rmngrc
  • 26
  • 4