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.

  • Worth looking at this, the fiddle seems like what you want to achieve: [http://stackoverflow.com/a/14835160/4045532](http://stackoverflow.com/a/14835160/4045532) – Corporalis Sep 22 '16 at 11:21
  • Possible duplicate of [How to bind to list of checkbox values with AngularJS?](http://stackoverflow.com/questions/14514461/how-to-bind-to-list-of-checkbox-values-with-angularjs) – BrTkCa Sep 22 '16 at 11:46

2 Answers2

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
  }
}
Hmahwish
  • 2,222
  • 8
  • 26
  • 45
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>
Shaishab Roy
  • 16,335
  • 7
  • 50
  • 68