0

I need one help.I need to get all checked data from the table row using Angular.js. I am explaining my code below.

<tr ng-repeat="gl in galleryDatas">
<td><input type="checkbox" name=""> {{$index+1}}</td>
<td><img ng-src="upload/{{gl.image}}" border="0" name="image" style="width:100px; height:100px;" /></td>
<td>{{gl.description}}</td>
</tr>

Here i need while user will clicked the check box the respective row data will retrieving into a array.Please help me.

2

2 Answers 2

0

Use ng-change on the checkbox

<td><input type="checkbox" ng-change="clickedRow(gl.checked)" name="" ng-model="gl.checked"></td>

In controller,

$scope.clickedRow = function(checked) {
 if (checked) {
  //add to the list
   } else {
 // remove from list
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

you can achieve by this process

in your controller:

$scope.galleryDatas = [
  {
        name: 'something',
        description: "name 1"
    },
    {
        name: 'another',
        description: "name 2"
    }
  ];

  $scope.checkedValue = [];

  $scope.saveInArray = function(index) {
    if($scope.galleryDatas[index].checked) {
      $scope.checkedValue.push($scope.galleryDatas[index]);
    } else {
       var newIndex = $scope.checkedValue.map(function(e) { return e.name; }).indexOf($scope.galleryDatas[index].name);
       // for compare instead of "name" you should use that field is unique. ie: e.uniqueField
       // and $scope.galleryDatas[index].uniqueField
       if(newIndex !== -1)
          $scope.checkedValue.splice(newIndex,1);
    }

  };

N.B: where checked row data store in $scope.checkedValue array and when unchecked then removed from $scope.checkedValue array

and Html:

<td><input type="checkbox" ng-model="gl.checked" ng-click="saveInArray($index)"> {{$index+1}}</td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.