AngularJS Select: Initial selection not working

85 Views Asked by At

I cannot figure out why the initial selection is not working in this code. Everything else is just fine. The options are all there, etc...

<select id="userEmail" class="form-control"
                            data-ng-init="userSelection = users[0]"
                            data-ng-model="userSelection"
                            data-ng-options="user.email for user in users">
                        </select>

Also the variant with userSelection = userSelection || users[0] does not work.

1

There are 1 best solutions below

2
On

Would make this just a comment, but can't yet.

Your code should work. I pretty copied it into this plnkr and it works just fine.

I guess just make sure you have all your controllers and whatnots set up correctly.

<select id="userEmail" class="form-control"
    data-ng-init="userSelection = users[5]"
    data-ng-model="userSelection"
    data-ng-options="user.email for user in users">
</select>
<hr>
{{ userSelection }}