Setting selected values for ng-options bound select elements Setting selected values for ng-options bound select elements angularjs angularjs

Setting selected values for ng-options bound select elements


If using AngularJS 1.2 you can use 'track by' to tell Angular how to compare objects.

<select     ng-model="Choice.SelectedOption"                     ng-options="choice.Name for choice in Choice.Options track by choice.ID"></select>

Updated fiddle http://jsfiddle.net/gFCzV/34/


You can use the ID field as the equality identifier. You can't use the adhoc object for this case because AngularJS checks references equality when comparing objects.

<select     ng-model="Choice.SelectedOption.ID"     ng-options="choice.ID as choice.Name for choice in Choice.Options"></select>


Using ng-selected for selected value. I Have successfully implemented code in AngularJS v1.3.2

<select ng-model="objBillingAddress.StateId"  >   <option data-ng-repeat="c in States" value="{{c.StateId}}" ng-selected="objBillingAddress.BillingStateId==c.StateId">{{c.StateName}}</option>                                                </select>