html:
<div><input type="checkbox" ng-click="updateSelection($event,row.entity.id)" ng-checked="isSelected(row.entity.id)">选择</div>
js:
$scope.selected = [];
$scope.updateSelection = function (event, id) {
var checkbox = event.target;
var action = (checkbox.checked ? 'add' : 'remove');
if (action == 'add' && $scope.selected.indexOf(id) == -1) {
$scope.selected.push(id);
}
if (action == 'remove' && $scope.selected.indexOf(id) != -1) {
var idx = $scope.selected.indexOf(id);
$scope.selected.splice(idx, 1);
}
console.log($scope.selected)
}
$scope.isSelected = function(id){
return $scope.selected.indexOf(id)>=0;
}
参考:https://blog.csdn.net/liaodehong/article/details/50531873