AngularJS ng-options default selected option

Ryan picture Ryan · Jun 5, 2014 · Viewed 40.2k times · Source

How can you set a default option with ng-options?

I've set this in the controller (using the controller as syntax):

this.myOption = this.myOptions[0];

However, that's still returning a blank default option:

<option value="?" selected="selected"></option>

How can I set the default option to the first value in my model ("Item 1")?

Here's a JSBin demo.

Answer

Yoshi picture Yoshi · Jun 5, 2014

either change:

ng-options="value.id as value.label ...

to:

ng-options="value as value.label ...

demo: http://jsbin.com/gewebeqo/4/


or use:

this.myOption = this.myOptions[0].id;

in the controller.

demo: http://jsbin.com/gewebeqo/3/