我有一个给定的对象数组,我想根据相关复选框将其对象添加到“选定”列表中。我怎么能设置它们而不必设置控制器太多。
这是使用单选框时可以正常工作的小提琴:http: //jsfiddle.net/JohannesJo/6ru2R/
JavaScript:
app = angular.module('app',[]);
app.controller('controller', function($scope){
$scope.aData = [
{i:1},
{i:2}
];
$scope.aSelected = [];
});
html:
<body ng-app="app">
<div ng-controller='controller'>
<input type = "checkbox" ng-model = "aSelected" value = "{{aData[0]}}">
<input type = "checkbox" ng-model = "aSelected" value = "{{aData[1]}}">
<div>test: {{oSelected}}</div>
</div>
</body>