ng-model与ng-click不兼容

时间:2013-07-03 22:21:31

标签: javascript angularjs

关于这个块的全部内容:

<div class="panel done-{{ todo.done }}" ng-repeat="todo in todos()" ng-click="changeStatus(todo)">
  <input type="checkbox" ng-model="todo.done"> {{ todo.title }}
</div>

删除外部ng - 单击该复选框工作正常,不这样做只需ng-click即可。当复选框没有改变状态时,Ng-click将改变复选框的值。

$scope.changeStatus = function(todo) {
  todo.done = ! todo.done;
};

2 个答案:

答案 0 :(得分:0)

ng-click应该在输入字段中输入:

<div class="panel done-{{ todo.done }}" ng-repeat="todo in todos()" >
  <input type="checkbox" ng-model="todo.done" ng-click="changeStatus(todo)"/> {{ todo.title }}
</div>

你的功能应该有!附加到变量的运算符或它将失败:

$scope.changeStatus = function(todo) {
  todo.done = !todo.done;
};

答案 1 :(得分:0)

现在就开始工作了。这可能有点难看,但它确实有效:

<div class="panel done-{{ todo.done }}" ng-repeat="todo in todos()" ng-click="changeStatus(todo)">
  <input type="checkbox" ng-model="todo.done" ng-click="changeStatus(todo)"> {{ todo.title }}
</div>