我使用了角度1.5.2
而我正试图绑定,我的select
就像这样:
<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>
但它没有用。当用户具有角色4时,它仍显示1?
答案 0 :(得分:2)
您应该在ng-model="employeeCtrl.employee.RoleId"
代码中使用select
而不是option
代码
<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>
请参阅PLUNKER DEMO
答案 1 :(得分:1)
将ngModel
放在select
元素上:
<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>