我有像这样的HTML代码
<select id="userGroups" name="userGroups" ng-model="userGroups" required class="form-control">
<option value="{{grp.groupId}}" ng-repeat="grp in groups">{{grp.groupName}}</option>
</select>
在我的控制器中我想设置默认值,但它不起作用
function CreateUserController($scope, grpList) {
$scope.groups = grpList.groupList; //it is loading correctly and dropdown is populating correctly
$scope.userGroups = "2";
}
我正在尝试将userGroups值设置为2,但它始终显示select
中的第一个选项答案 0 :(得分:1)
这里最好的选择是使用ng-options:
<select ng-model="userGroups"
ng-options="group.groupId as group.groupName for group in groups">
</select>