在有角度的ng重复中嵌套ng选项
Nested ng-option inside angular ng-repeat
Im当前正试图将<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>
在控制器中,im将项目添加到具有选定项目的新列表中。我还想将下拉列表中的值作为新值添加到控制器中的列表中。
$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" }
]
}
]
简而言之,当我点击"添加"时,我需要从下拉列表中选择的值,即当前类型模型的值。
这就是它现在的样子,但它不起作用。我知道我必须得到正确的模型,也许可以通过$index跟踪项目列表,但在网上搜索了一整天的解决方案后,我仍然停滞不前!
感谢所有的帮助。
-谢谢!
ps。如果问题中遗漏了什么,或者需要更多的东西来解决这个问题,请发表评论。
首先,将下拉列表更改为
<select ng-options="usertype in item.userGroups" ng-model="item.recipientType">
然后,当您触发add函数时,项的属性recipientType
已经设置。
$scope.add = function (item) {
console.log(item.recipientType);
$scope.selected.push(item);
};
相关文章:
- 嵌套ng重复angularjs
- 将angular与嵌套ng重复使用:
- AngularJS - 嵌套的ng-重复选择/选项,获取/设置所选值
- 嵌套在 ng 重复中的拼接数组
- 如何重置嵌套ng重复
- 嵌套ng中的Angularjs单选按钮重复未选中
- 如何在同一个表中显示这两个嵌套ng重复的元素
- AngularJS - 如何从嵌套的ng-repeat将id传递给api
- 在AngularJS 1.5.x中嵌套列表并更正ng模型和ng值
- 带有动态输入的嵌套ng重复
- 使用复选框嵌套ng重复
- 多维数组的嵌套ng重复
- 更改嵌套ng重复中的$http参数
- 如何访问嵌套的表单ng包含范围/字段
- Angular 1.3+ui路由器+生成器ng poly嵌入嵌套(?)视图不起作用
- AngularJS-如何在嵌套ng重复中对已筛选的孙项求和
- 使用嵌套ng中带有单选按钮的ng模型重复不起作用
- angular js中嵌套ng include内的表单
- 验证嵌套在ng中的输入元素repeat也用于页面加载,而不仅仅用于更改
- 使用AngularJS处理嵌套ng重复.无法通过ng单击来获取按钮