Odd bug with ng-model and select/option


#1

I’m having an issue with the ionic select menu and using ng-model with a default option. This code will not default to the selected value:

<select ng-model="input.test">
    <option>Select 1</option>
   <option selected>Select 2</option>
</select>

But if I lose the ng-model in the code, it then defaults to Select 2.

<select>
    <option>Select 1</option>
   <option selected>Select 2</option>
</select>

Can anyone shed some light as to why this may be happening?


#2

Upon further reviewing, I found the answer to my problem. It needed to be:

<select ng-model="input.test" ng-init="input.test='Select 2'">
    <option>Select 1</option>
   <option ng-selected="true">Select 2</option>
</select>

ng-selected would show that Select 2 was actually selected, but would show as undefined. ng-init allows for the value to also be associated. Thanks for the help and hope this helps someone else