angular ng-repeat 内嵌套了 ng-option
Nested ng-option inside angular ng-repeat
我目前正在尝试将 <select>
嵌套在带有 ng-repeat
的 div
中
像这样:
<li ng-repeat="item in items >
<div class="row">
<div class="col-xs-7">
<span ng-bind="item.Name"></span>
</div>
<div class="col-xs-4 modal-body--ul--li__dropdown_container">
<select ng-model="typemodel" >
<option ng-repeat="usertype in item.userGroups"></option>
</select>
</div>
<div class="col-xs-1">
<a ng-click="add(item)"></a>
</div>
</div>
</li>
我在控制器中将项目添加到包含选定项目的新列表中。我还想将下拉列表中的值作为新值添加到控制器的列表中。
$scope.add = function (item) {
//New value with the value from the dropdown
item.recipientType = typemodel;
$scope.selected.push(item);
};
榜单:
$scope.items = [
{
"Name":"Name1",
"userGroups":[
{ "type": "gruop1" },
{ "type": "gruop2" },
{ "type": "group3" }
]
},
{
"Name":"Name2",
"userGroups":[
{ "type": "gruop1" },
{ "type": "gruop2" },
{ "type": "group3" }
]
}
]
简而言之,当我点击 "add" 时,我需要从下拉列表中选择值,即当前类型模型的值。
这是它现在的样子,但它不起作用。我知道我必须获得正确的模型并且可能通过 $index 跟踪项目列表,但是在网上搜索了一整天的解决方案之后,我仍然卡住了!
感谢所有帮助。
-谢谢!
ps。如果问题中缺少某些内容,或者需要更多内容来解决此问题,请发表评论。
首先,将下拉列表更改为
<select ng-options="usertype in item.userGroups" ng-model="item.recipientType">
然后当你触发添加功能时,项目的属性 recipientType
已经设置。
$scope.add = function (item) {
console.log(item.recipientType);
$scope.selected.push(item);
};
我目前正在尝试将 <select>
嵌套在带有 ng-repeat
div
中
像这样:
<li ng-repeat="item in items >
<div class="row">
<div class="col-xs-7">
<span ng-bind="item.Name"></span>
</div>
<div class="col-xs-4 modal-body--ul--li__dropdown_container">
<select ng-model="typemodel" >
<option ng-repeat="usertype in item.userGroups"></option>
</select>
</div>
<div class="col-xs-1">
<a ng-click="add(item)"></a>
</div>
</div>
</li>
我在控制器中将项目添加到包含选定项目的新列表中。我还想将下拉列表中的值作为新值添加到控制器的列表中。
$scope.add = function (item) {
//New value with the value from the dropdown
item.recipientType = typemodel;
$scope.selected.push(item);
};
榜单:
$scope.items = [
{
"Name":"Name1",
"userGroups":[
{ "type": "gruop1" },
{ "type": "gruop2" },
{ "type": "group3" }
]
},
{
"Name":"Name2",
"userGroups":[
{ "type": "gruop1" },
{ "type": "gruop2" },
{ "type": "group3" }
]
}
]
简而言之,当我点击 "add" 时,我需要从下拉列表中选择值,即当前类型模型的值。
这是它现在的样子,但它不起作用。我知道我必须获得正确的模型并且可能通过 $index 跟踪项目列表,但是在网上搜索了一整天的解决方案之后,我仍然卡住了!
感谢所有帮助。
-谢谢!
ps。如果问题中缺少某些内容,或者需要更多内容来解决此问题,请发表评论。
首先,将下拉列表更改为
<select ng-options="usertype in item.userGroups" ng-model="item.recipientType">
然后当你触发添加功能时,项目的属性 recipientType
已经设置。
$scope.add = function (item) {
console.log(item.recipientType);
$scope.selected.push(item);
};