0

I'm using angular 1.5.2 and I'm trying to bind ,my select like this:

<label>Role</label>
<div class="form-group">
    <div>
        <select id="role" class="form-control" name="role" >
            <option value="1" ng-model="employeeCtrl.employee.RoleId" name="role" id="intern">Stagiair</option>
            <option value="3" ng-model="employeeCtrl.employee.RoleId" name="role" id="employee">Werknemer</option>
            <option value="4" ng-model="employeeCtrl.employee.RoleId" name="role" id="companyadmin">Bedrijfadmin</option>
        </select>
    </div>
</div>

But it's not working. When a user has role 4 it still shows 1 ?

1
  • The ng-model should be on the select tag, and it looks a bit strange. Can you post your controller code and show where you initiate this variable? Commented Mar 28, 2016 at 14:19

2 Answers 2

2

you should use ng-model="employeeCtrl.employee.RoleId" in select tag instead of option tag

   <select id="role" class="form-control" ng-model="employeeCtrl.employee.RoleId" >
        <option value="1" name="role" id="intern">Stagiair</option>
        <option value="3" name="role" id="employee">Werknemer</option>
        <option value="4" name="role" id="companyadmin">Bedrijfadmin</option>
    </select>

See PLUNKER DEMO

1

Put the ngModel on the select element:

<select id="role" class="form-control" name="role" ng-model="employeeCtrl.employee.RoleId">
    <option value="1" name="role" id="intern">Stagiair</option>
    <option value="3" name="role" id="employee">Werknemer</option>
    <option value="4" name="role" id="companyadmin">Bedrijfadmin</option>
</select>
1
  • Then the selected role is nothing. I've checked employeeCtrl.employee.RoleId and that is 4 so I would expect Bedrijfadmin to be selected.
    – Jamie
    Commented Mar 28, 2016 at 13:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.