答案 0 :(得分:3)
你不需要ng-selected
内的花括号:
<option value="m" ng-selected="GenderInfo.Gender =='m'">Male</option>
<option value="f" ng-selected="GenderInfo.Gender =='f'">Female</option>
答案 1 :(得分:2)
尝试如下:
<body ng-app ng-controller="AppCtrl">
<div ng-click="setGender()">Set</div>
<select name="Gender" class="form-control">
<option value="m" ng-selected="GenderInfo.Gender =='m'">Male</option>
<option value="f" ng-selected="GenderInfo.Gender =='f'">Female</option>
</select>
</body>
ngSelected
不需要{{}},因为它会评估给定的表达式。
希望这有帮助。我用你的jsFiddle对它进行了测试,看起来效果很好。
答案 2 :(得分:2)
使用ng-options查看我的code:
<select ng-model="GenderInfo" name="Gender" class="form-control" ng-options="g.value as g.title for g in gender">
使用Javascript:
$scope.gender = [
{value:'m',title:'Male'},
{value:'f',title:'Female'}
];
$scope.GenderInfo = $scope.gender[0].value;//Set Default gender
答案 3 :(得分:0)
您可以ng-options
使用Example
<select ng-init="model.Gender = genders[0].Key" name="Gender" class="form-control" ng-model="model.Gender" ng-options="g.Key as g.Gender for g in genders">