I am using Ionic Framework and angularjs to develop one application. Here I am using checkbox inside ng-repeat. Using this I can able to insert checkbox checked values into array. But It is inserting like strings.
Like ["coding","testing"] .
But I want it like objects.
Like ["object","object"] . Inside that object values should be there.
Html code is
<div class="action-checkbox" ng-repeat="task in projecttasks">
<h3>{{task.projectName}}</h3>
<ul>
<li ng-repeat="subtask in task.subTasks" ng-click="addprjtaskList(task,subtask)">
<input id="{{subtask._id}}" name="{{subtask._id}}" type="checkbox" value="{{subtask.subTaskName}}" ng-checked="selection.indexOf(subtask.subTaskName) > -1" ng-click="toggleSelection(subtask.subTaskName)" class="hide"/>
<label for="{{subtask._id}}" >
{{subtask.subTaskName}}
</label>
</li>
</ul>
</div>
controller code is
$scope.selection = [];
// toggle selection for a given fruit by name
$scope.toggleSelection = function toggleSelection(fruitName) {
var idx = $scope.selection.indexOf(fruitName);
// is currently selected
if (idx > -1) {
$scope.selection.splice(idx, 1);
console.log($scope.selection);
}
// is newly selected
else {
$scope.selection.push(fruitName);
console.log($scope.selection);
}
};
can anyone help me to do this..