【发布时间】:2017-04-14 06:36:31
【问题描述】:
有问题,这里的情况:
当我取消选中第二个复选框时,我想取消选中第一个复选框。
可以说,默认情况下,两个复选框都被选中。当我点击第二个复选框时,我希望第一个复选框也取消选中。
HTML:
<ion-checkbox ng-model="firstCheckbox">First Checkbox</ion-checkbox>
<ion-checkbox ng-model="secondCheckbox" ng-change="uncheckFirstCheckbox(secondCheckbox)">Second Checkbox</ion-checkbox>
JS:
$scope.uncheckFirstCheckbox = function(secondCheckbox) {
if(secondCheckbox.checked === false) {
$scope.firstCheckbox = false;
};
};
$scope.firstCheckbox 变为 false,但在 HTML 中仍未选中。
我可以知道问题出在哪里吗?
【问题讨论】:
-
试试
if(!$scope.secondCheckbox) { $scope.firstCheckbox = false; };,不要将函数调用中$scope上的值作为一个好的做法来传递 -
感谢您的提示 :) @entre
标签: angularjs checkbox ionic-framework