//初始数据格式
$scope.pigdatalists = [
{"id":1,"checked":false},{"id":2,"checked":false},
{"id":3,"checked":false}
];
//全选
scope.checkearall = false;//默认不是全选状态
scope.checkearAll = function(checked){
//改变全选按钮的状态
scope.checkearall = !scope.checkearall;
//循环操作数据,将每条数据里面的checked值跟全选状态的值对应起来
angular.forEach(scope.pigdatalists,function(value,key){
value.checked = scope.checkearall;
});
};
//单选
scope.checkearItemFun = function(checked,index){
scope.pigdatalists[index].checked = checked;
}
<ul class="">
<li class="col-xs-12">
<div class="col-xs-3 aligncenter" >
<input type="checkbox" class="pigdatavalitemcheck" name="checkpig" id="checkallpigdata" ng-model="checkearall" ng-click="checkearAll(checkearall)" /><label for="checkallpigdata"> 全选</label>
</div>
<span class="pigdatavalitem col-xs-3">耳号</span>
<span class="pigdatavalitemblock col-xs-3" >栋舍</span>
<span class="pigdatavalitemfield col-xs-3" >栏位</span>
</li>
<li ng-repeat="item in pigdatalists" class="col-xs-12" ng-class="{'activedbackgroundcolor2':item.checked}">
<div class="col-xs-3 aligncenter">
<input type="checkbox" class="pigdatavalitemcheck" name="checkpig" ng-model="item.checked" ng-click="checkearItemFun(item.checked,$index)" />
</div>
<span class="pigdatavalitem col-xs-3" ng-bind="item.price"></span>
<span class="pigdatavalitemblock col-xs-3" ng-bind="item.name"></span>
<span class="pigdatavalitemfield col-xs-3" ng-bind="item.name"></span>
</li>
</ul>