我有一个带有coloumn性别的表。在加载表单时默认从数据库设置。 但是当我点击编辑按钮时,下拉列表会出现性别'男性'和'女性',但缺少默认值。
这是代码
<td data-title="'<?php echo $this->lang->line('label_gender'); ?>'" sortable="'gender'" filter="{ 'gender': 'text' }">
<span ng-if="!staff_reg.$edit">{{staff_reg.gender}}</span>
<div ng-if="staff_reg.$edit">
<select class="form-control" ng-model="staff_reg.gender">
<option value="male" ng-selected="staff_reg.gender=='male'" ><?php echo $this->lang->line('label_male'); ?></option>
<option value="female" ng-selected="staff_reg.gender=='female'"><?php echo $this->lang->line('label_female'); ?></option>
</select>
</div>
</td>
答案 0 :(得分:2)
您的代码似乎完全没问题。请与这个工作小提琴交叉验证。 http://jsfiddle.net/dakra/U3pVM/
<div ng-app>
<div ng-controller="TodoCtrl" >
<span>{{greeting}}</span>
<select class="form-control" ng-model="staff_reg.gender">
<option value="male" ng-selected="staff_reg.gender=='male'" >Male</option>
<option value="female" ng-selected="staff_reg.gender=='female'">Female</option>
</select>
<span>{{staff_reg.gender}}</span>
</div>
</div>
function TodoCtrl($scope) {
$scope.greeting = "Hello";
$scope.staff_reg = {gender : 'female'};
}