javascript - All checkboxes getting checked even if one is checked -
i'm making basic todo app in angularjs. here's code that's used create new todo checkbox
<div class="container" ng-controller = 'controller' > <h3>enter todo </h3> <input type="text" ng-model = 'new'> <button ng-click = 'add();' ng-disabled="status();">add</button> <div ng-repeat = "i in todo" > <input type="checkbox" ng-model = "todo.done" /> <label>{{i.name}}</label> </div> </div>
the problem checkboxes checked when check one
here's controller module
todoapp.controller('controller',['$scope',function($scope){ $scope.new = ''; $scope.todo = []; $scope.add = function(){ $scope.todo.push({name : $scope.new, done: false}); console.log($scope.todo); $scope.new = ''; }; $scope.status = function(){ return !(/\s+/.test($scope.new)); };
ng-model = "i.done"
should solve problem. in version ng-model = "todo.done"
todo array , angular creates property on fly, when it's used first time. way of checkboxes connected property, that's why checking 1 checkbox affects of them.
Comments
Post a Comment