AngularJS. When select have ng-model attribute, ng-selected not working
Don't use ngSelected with ngRepeat. Go with ngOptions:
<body ng-controller="TestController">
Selected item must be {{ array[test-1].name }}
<select ng-model="myModel" ng-options="item.id as item.name for item in array">
<option value="">Choose item..</option>
</select>
</body>
Don't use ngSelected
with ngModel
From the Docs:
Note:
ngSelected
does not interact with the<select>
andngModel
directives, it only sets the selected attribute on the element. If you are usingngModel
on the select, you should not usengSelected
on the options, asngModel
will set the select value and selected options.— AngularJS ng-selected API Reference
See additional Docs:
- Using
ng-repeat
to generateselect
options - Using select with
ng-options
and setting a default value
See Stackoverflow:
- Using
ng-repeat
to generate select options (with Demo)