$scope.data = [{
'id': '1',
'itemName': 'mousepad',
'price': '20'
}, {
'id': '2',
'itemName': 'keyboard',
'price': '20'
}, {
'id': '3',
'itemName': 'charger',
'price': '20'
}]
$scope.checkedTrue = function(h) {
$scope.demoArr = [];
$scope.demo = [];
$scope.demoArr.push(h);
function check() {
var deee = $.grep($scope.demoArr, function(record) {
console.log('iijjdkkdkkdkd======>', record);
return record
});
$scope.checkDemo = deee;
}
check();
$scope.demo.push($scope.checkDemo);
};
<table class="table m-t-30">
<thead>
<tr>
<th>#</th>
<th>ItemName {{selected}}</th>
<th>ItemPrice</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="tic in data track by $index">
<td>
<input id="checkbox2" type="checkbox" ng-model="selected[tic.id]" ng-change="checkedTrue(tic)"/>
</td>
<td><span>{{tic.itemName}}</span></td>
<td><span>{{tic.price}}</span></td>
</tr>
</tbody>
</table>
I currently have an array displayed using ng-repeat:
var data = [{
'id': '1',
'itemName': 'mousepad',
'price': '20'
}, {
'id': '2',
'itemName': 'keyboard',
'price': '20'
}, {
'id': '3',
'itemName': 'charger',
'price': '20'
}];
In each row, there are checkboxes. When a user checks a checkbox, I want to extract that particular row object and add it to a new array.
For example:
Add only checked objects into another array named Checked
var Checked = [{
'id': '1',
'itemName': 'mousepad',
'price': '20'
},{
'id': '3',
'itemName': 'charger',
'price': '20'
}];
If the user unchecks a checkbox, I want to remove the corresponding object from the Checked array.
If the checkbox is checked again, the object should be added back to the Checked array.