Monday, June 24, 2013

AngularJS - Draw a Select with a default option

In the following example, we set a default option for our users to see. We could leave it blank but it would not help our user. We could also preselect one of our options as the default one but sometimes we do not want to influence or dictate our user's selection.

    <form name="myForm">
<select ng-options="color for color in ['red', 'blue', 'yellow']" ng-model="color1">
<option value="" selected>--Please select your color--</option>
</select>
</form>
Note: it is important that our default options has value set to nothing.

Useful links:

Working Example: Plunkr

1 comment: