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

Sign up to request clarification or add additional context in comments.

Comments

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 Comment

Then the selected role is nothing. I've checked employeeCtrl.employee.RoleId and that is 4 so I would expect Bedrijfadmin to be selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.