[当我选中主复选框时,应选中所有子复选框,并且还应在选中复选框时显示其内容,否则不应显示其内容,但问题是选中了子复选框,但是如果我手动选中子复选框,则当我选中主复选框时,不会显示其内容。
<!DOCTYPE html>
<html>
<head>
<title>Angular Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body data-ng-app="">
<table>
<tr>
<td>
<input type="checkbox" data-ng-model="parent"/>
</td>
<td data-ng-show="parent" class="left">
It's master
</td>
</tr>
<tr>
<td>
<input type="checkbox" data-ng-model="child_1" data-ng-checked="parent"/>
</td>
<td data-ng-show="child_1">
It's child 1
</td>
</tr>
<tr>
<td>
<input type="checkbox" data-ng-model="child_2" data-ng-checked="parent"/>
</td>
<td data-ng-show="child_2">
It's child 2
</td>
</tr>
</table>
</body>
</html>
<input type="checkbox" data-ng-model="parent" data-ng-change="child_1= parent;
child_2=parent;" />
请点击click查看代码。
相反,为您的父母处理ng-checked:
<input type="checkbox" data-ng-model="parent" ng-checked="parentChanged()"/>
并且在您的控制器中,将每个孩子的模型设置为父值:
$scope.parentChanged = function(){ child_1 = parent; child_2 = parent; }
还从视图的子节点中删除data-ng-checked =“ parent”。
<input type="checkbox" data-ng-model="child_1"> ... <input type="checkbox" data-ng-model="child_2">
<input type="checkbox" data-ng-model="child_1" data-ng-checked="child_1 = parent"/>
您可以看到如何做:Here