1
The bug is this, I have 2 checkboxes
, by triggering the first the other is automatically marked, the second checkbox
owns the tag ng-change
calling a function in the controller
, the problem is, when I set the second checkbox
first, the ng-change
works and makes the call
correct function, if I trigger the first checkbox
automatically marking the second, when you uncheck the second, it no longer calls the function, it calls the first click
in the second checkbox
,
I was able to reproduce the error
angular.module('ToDo', [])
.controller('ToDoController', function ($scope) {
$scope.change = function(){
console.log("changed");
};
});
<html ng-app='ToDo'>
<head>
<title>My Angular To-Do App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body ng-controller="ToDoController">
<input type="checkbox" ng-model="ck1" />
<br/>
<input type="checkbox" ng-model="ck2" ng-change="change()" ng-checked="ck1"/>
</body>
</html>
There are several ways to solve this problem. Do you really need the first checkbox model to have a different name than the second? What is the need of the
change
. Wouldn’t it be better to use one$scope.$watch
rather than a function that is captured byng-change
?– Wallace Maxters