如何获取使用循环中的ng选项实现的Select框的值
How to get the value of a Select box implemented using ng-options which is inside a loop?
我有一个显示客户信息的列表页面,每行客户中都有一个选择框,其中包含一些选项,如编辑、取消、删除等。客户使用ng repeat指令显示,具有上述选项的选择框使用ng选项实现。
我试图从下拉列表中获取每行所选项的值,但它不起作用,当我将选择框代码片段粘贴到循环外时,代码起作用了。
这是我显示客户的代码
<table class="table display table-striped table-bordered" ng-table="tableParams">
<tr ng-repeat="customer in $data | filter: search | filter :name">
<td data-title="'Reseller ID'" sortable="'ResellerId'" >
{{customer.ResellerId}}
</td>
<td data-title="'Reseller Name'" sortable="'ResellerName'">
{{customer.ResellerName}}
</td>
<td data-title="'Customer ID'" sortable="'CustomerID'">
{{customer.CustomerID}}
</td>
<td data-title="'Customer Name'" sortable="'CustomerName'">
{{customer.CustomerName}}
</td>
<td data-title="'Status'" sortable="'Status'">
{{customer.Status}}
</td>
<td data-title="'Available Funds'" sortable="'AvailableFunds'">
{{customer.AvailableFunds}}
</td>
<td data-title="'Created Date'" sortable="'CreatedDate'">
{{customer.CreatedDate}}
</td>
<td>
<form name="statusForm">
<select class="form-control status" ng-model="actionslist" name="actions" ng-options="action.name for action in action_options" ng-change="editCustomer()">
<option value="">Select Action</option>
</select>
</form>
</td>
<td><a href="#" class="btn btn-info" data-toggle="tooltip" data-original-title="View Domains"><i class="fa fa-desktop"></i></a> <a href="#" class="btn btn-warning" data-toggle="tooltip" data-original-title="View Subscriptions"><i class="fa fa-rss"></i></a> <a href="#" class="btn btn-success" data-toggle="tooltip" data-original-title="Login"><i class="fa fa-sign-in"></i></a> </td>
</tr>
</table>
这是我的角度代码
var CustomerController = function ($scope, $filter, $http, ngTableParams) {
$scope.action_options = [{
name: 'Edit',
value: 'edit'
}, {
name: 'Suspend',
value: 'suspend'
}, {
name: 'Cancel',
value: 'cancel'
}, {
name: 'Delete',
value: 'delete'
}, {
name: 'Reset Password',
value: 'reset'
}];
$scope.editCustomer = function () {
//$scope.itemList=[];
alert($scope.item.value);
//alert($scope.selected.actions);
}
}
有人能告诉我我在这里犯了什么错误吗?
它将通过您的ng型号保存
$scope.editCustomer = function () {
alert($scope.actionslist);
}
工作小提琴
试试这个:
<select ng-model="action" ng-options="obj.value as obj.name for obj in action_options"></select>
看看这个答案https://stackoverflow.com/a/12140310/1530725
相关文章:
- AngularJs列表ng单击以选择选项转换
- 如何使用AngularJs禁用ng选项中的选项
- 如何将ng选项的索引作为angularJs中的值传递给模型
- AngularJS ng选项在选择一个选项后删除了默认的空白值
- 当使用select作为标签时,如何使用ng选项禁用angularjs中的选项
- 角度引导选项卡ng如果错误
- 从服务器获取数据并在选择控件中使用ng选项无法显示选项
- ng选项-用vm替换$scope
- Angularjs-设置不带ng选项的select的默认值
- 角度去抖动(ng模型选项)不起作用
- ng选项-传递键而不是值
- Angular:如何使用ng选项进行四个单独的选择
- 选择框中带有关联的ng模型,选项中带有ng重复
- 使用ng选项,我如何筛选准确解释给定值的内容
- 角度Ng选项错误
- Angular.js通过对象关键点上的ng选项进行跟踪
- 选择/选项 ng-model 未绑定 ng-selected
- Angularjs 选择选项 ng 选择为分配值选择空白选项
- <选项 ng-repeat value={{object}}> 如何强制角度将对象推入模型
- 删除空白选项ng repeat和过滤后的ng选项