0

How to get dynamic data from checkbox in angularjs? I trying to use below code but getting error :

TypeError: Cannot read property '0' of undefined

HTML

<tr ng-repeat="procForAcnts in procForAcnt">
                    <td>{{procForAcnts[0]}}</td>
                    <td><input type="checkbox" ng-model="procNums[$index]" ng-change="test()" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td>
                    <td>{{procForAcnts[3]}}</td>
                    <td>{{procForAcnts[1]}}</td>
                    <td>{{procForAcnts[5]}}</td>
                    <td>{{procForAcnts[2]}}.00</td>
                    <td><center>--</center></td>
                    <td>{{procForAcnts[7]}}</td>
                    </tr>

JS

$scope.test = function() {
var len= $scope.procForAcnt.length;
alert(len); //working
for(i=0; i<len; i++){
alert($scope.procNums[i]);
}
}
Pratyush Pranjal
  • 544
  • 6
  • 26

1 Answers1

0

Although, you have not posted complete code here. All I can suggest you is to send parameter to your test method.

Replace:

<td><input type="checkbox" ng-model="procNums[$index]" ng-change="test()" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td>

With:

<td><input type="checkbox" ng-model="procNums[$index]" ng-change="test(procNums[$index])" value="{{procForAcnts[2]}}"> {{procForAcnts[4]}}</td>

Then receive the value in your test method as a parameter:

$scope.test = function(selectedValue) {
   alert(selectedValue);
};

Please let me know if it helps!

Anadi Sharma
  • 295
  • 1
  • 8