lundi 21 décembre 2015

How use checkbox properly inside ng-repeat in angularjs?

I am using ionic framework and angularjs for one app. I am using checkboxes inside ng-repeat. The issue is, if I check the checkbox, it is getting added to the array. If I uncheck it is not getting removed from that array.

The html code is

<div class="action-checkbox" ng-repeat="task in alltasks">
  <h3>{{task.taskName}}</h3>
  <ul>
    <li ng-repeat="subtask in task.subTasks" ng-click="addList(task,subtask)">
      <input id="{{task._id}}_{{subtask._id}}" name="{{task._id}}_{{subtask._id}}" type="checkbox" value="{{subtask.subTaskName}}" ng-checked="subtask.checked" ng-model="slectedTasks" class="hide"/>
      <label for="{{task._id}}_{{subtask._id}}" > 
        {{subtask.subTaskName}}
      </label>
    </li>
  </ul>
</div>

My controller code is

$scope.addList = function(task,subtask){
       subtask.checked= !(subtask.checked);
       var data = {
       "task_id": task._id,
       "subTaskName": subtask.subTaskName,
    };     
        if(subtask.checked){
         selectedMap.push(data);
        }
    }

can anyone help me to resolve this..




Aucun commentaire:

Enregistrer un commentaire