watch监听 chechbox 全选

// 监控全选checkbox的状态
$scope.$watch('AllCheck', function (newValue, oldValue) {

// 第一次不执行
if (newValue === oldValue) { return; }

var dd = $scope.FamousRes;
for (var value in dd) {
dd[value].Checked = $scope.AllCheck;
}
});

<div class="section mt20 padding20">
<div class="text-right"><a href="javascript:void(0)" class="btn-u btn-u-yellow" ng-click="saveRes()">加入我的听课列表</a></div>
<table class="table table-bordered">
<thead>
<tr>
<th><input type="checkbox" ng-model="AllCheck"></th>
<th>标题</th>
<th>主讲人</th>
<th>来源</th>
<th>学科</th>
<th>年级</th>
<th>操作</th>
</tr>
</thead>

<tr ng-show="!FamousRes||FamousRes.length==0">
<td colspan="7"><b>暂无数据</b></td>
</tr>
<tr ng-repeat="item in FamousRes">
<td>
<input type="checkbox" ng-model="item.Checked" ng-hide="item.State"><img src="/Areas/LA/Content/images/hui.png" ng-show="item.State" />
</td>
<td title="{{item.CourseName}}" ng-bind="item.CourseName.substring(0,10)"></td>
<td title="{{item.TeacherName}}" ng-bind="item.TeacherName ?item.TeacherName.substring(0,4):'未知'"></td>
<td title="{{item.OrgName}}" ng- ng-bind="item.OrgName ? item.OrgName:'未知'"></td>
<td ng-bind="item.SubjectName" title="{{item.SubjectName}}"></td>
<td ng-bind="item.GradeName" title="{{item.GradeName}}"></td>
<td><a ng-if="item.State" class="btn btn-default btn-sm w100">已添加</a><a ng-if="!item.State" class="btn btn-success btn-sm w100">未添加</a></td>
</tr>

</table>

watch:还有一个参数,true,只要参数发生变化就执行

上一篇:Feign配置日志的打印级别


下一篇:SSM框架的配置Spring+Springmvc +Mybatis