The order between ng-model and ng-click seems different, and you probably shouldn't rely on it. Instead, you can do something like this:
<div ng-app="myApp" ng-controller="Ctrl"> <li ng-repeat="todo in todos"> <input type='checkbox' ng-model="todo.done" ng-click='onCompleteTodo(todo)'> {{todo.text}} {{todo.done}} </li> <hr> task: {{current.text}} <hr> <h2>Wrong value</h2> done: {{current.done}} </div>
And your script:
angular.module('myApp', []) .controller('Ctrl', ['$scope', function($scope) { $scope.todos=[ {'text': "get milk", 'done': true }, {'text': "get milk2", 'done': false } ]; $scope.current = $scope.todos[0]; $scope.onCompleteTodo = function(todo) { console.log("onCompleteTodo -done: " + todo.done + " : " + todo.text);
What makes it different every time you click a field, it sets that field to "current" and then displays these values ββin the view. http://jsfiddle.net/QeR7y/
Manny D Oct 21 '13 at 14:34 2013-10-21 14:34
source share