单击复选框并调用ng-click:在ng-click插入之前不会更新模型,因此在UI中错误地显示了复选框的值:
这在AngularJS 1.0.7中有效,在Angualar 1.2-RCx中似乎已损坏。
<div ng-app="myApp" ng-controller="Ctrl">
<li ng-repeat="todo in todos">
<input type='checkbox' ng-click='onCompleteTodo(todo)' ng-model="todo.done">
{{todo.text}}
</li>
<hr>
task: {{todoText}}
<hr><h2>Wrong value</h2>
done: {{doneAfterClick}}
和控制器:
angular.module('myApp', [])
.controller('Ctrl', ['$scope', function($scope) {
$scope.todos=[
{'text': "get milk",
'done': true
},
{'text': "get milk2",
'done': false
}
];
$scope.onCompleteTodo = function(todo) {
console.log("onCompleteTodo -done: " + todo.done + " : " + todo.text);
$scope.doneAfterClick=todo.done;
$scope.todoText = todo.text;
};
}]);
带有Angular 1.2 RCx的破碎小提琴-http: //jsfiddle.net/supercobra/ekD3r/
使用Angular 1.0.0的工作混蛋-http: //jsfiddle.net/supercobra/8FQNw/