Select dropdown is not selecting ng-model with ng-options

96 views Asked by At

Very new to angular and currently stock in something

I have a dropdown that is set up like this

<div class="col-md-3" ng-repeat="item in templateCtrl.template.templateDetails">
<select class="form-control" ng-model="item.categoryID" ng-options="category.categoryName for category in templateCtrl.categories track by category.categoryID"></select>
</div>

It populates the dropdown but item.categoryID (all values are 1) is not selected. Help on this matter will be greatly appreciated

1

There are 1 answers

1
nircraft On

You need to fix a few things in your <select> element: use category.id as category.name in your ng-options.

ng-options="category.id as category.name for category in templateCtrl.categories track by category.categoryID"

If you want one of the options to be pre selected when loading the page or view you can do it with ng-init. In there you can set the model of that select to the value that has to be selected.