Angularjs 为什么选择的项目没有被填充
这是我的html代码Angularjs 为什么选择的项目没有被填充,angularjs,Angularjs,这是我的html代码 <select id="userGroups" name="userGroups" ng-model="userGroups" class="form-control"> <option value="{{grp.groupId}}" ng-repeat="grp in groups">{{grp.groupName}}</option> </select> 为什么选项没有被弹出 好的,在填充视图之前,我已经更改了控
<select id="userGroups" name="userGroups" ng-model="userGroups" class="form-control">
<option value="{{grp.groupId}}" ng-repeat="grp in groups">{{grp.groupName}}</option>
</select>
为什么选项没有被弹出
好的,在填充视图之前,我已经更改了控制器以解析组列表,但它仍然没有显示
MYApp.controller('CreateUserController', ['$scope', 'groupList', function($scope, groupList) {
$scope.groups = groupList;
debugger; //here I can see groups has objects which I need to display
}]);
但仍然没有加载下拉列表…根据您必须使用的角度j
ng选项
。ng repeat
不支持此用例:
ngOptions
为
元素提供了迭代器功能,当您希望将select
模型绑定到非字符串值时,应使用该迭代器来代替ngRepeat
。这是因为option元素目前只能绑定到字符串值
正如Martin所说,您需要使用ng选项 它应该是这样的:
<select id="userGroups"
name="userGroups"
ng-model="userGroups"
ng-options="grp.groupId as grp.groupName for grp in groups"
class="form-control">
</select>
你能发帖吗?$scope.groups
它的回报承诺中你得到了什么。。。。我通过将调试器放在.get()行之后进行了检查。。。但数据加载完成后,它不应自动更新$scope.groups?TypeError:undefined不是functioncontroller代码更新,但页面上仍然没有结果…:(将此添加到下面,选择并查看它呈现的内容:{groups | json}}}thx,以解释如何通过grp.groupId将值和文本设置为grp.groupName
<select id="userGroups"
name="userGroups"
ng-model="userGroups"
ng-options="grp.groupId as grp.groupName for grp in groups"
class="form-control">
</select>