0

I want to alert check box value one by one. I have 5 checkbox in the list. I want to get value of selected check box.

View

<ul class="ul-list-10">
     <li ng-repeat="assetType in assetTypeList">
          <input type="checkbox" ng-model="assetType.checked" ng-click="fnChangeAssetType(assetType)" value="{{assetType.Id}}" />
     </li>
 </ul>

JS

angular.forEach($scope.assetTypeList, function (item) {
                      //put your code here
 });
S. S. Rawat
  • 5,943
  • 4
  • 43
  • 59
  • 2
    you can not use `ng-model` inside `ng-repeat` in this case. Its bind `assetType.checked` for all checkbox, if you checked any checkBox you get all selected. – gaurav bhavsar Sep 14 '15 at 12:42
  • Provide `assetTypeList`, so its help to find solution. – gaurav bhavsar Sep 14 '15 at 12:45
  • Please check this [thread](http://stackoverflow.com/questions/14514461/how-can-angularjs-bind-to-list-of-checkbox-values) in order to know the different ways in which you can achieve it depending upon your data model. – road2victory Sep 14 '15 at 13:09

1 Answers1

1

By the way ,you can take value on click

Angularjs code:

var app = angular.module('myapp',[]);
app.controller('myctrl',function($scope){
 $scope.assetTypeList=[{id:1,checked:false},{id:2,checked:false},{id:3,checked:false},{id:4,checked:false}];
    $scope.fnChangeAssetType=function(val){
      alert(val.id);
    }
});

HTML

<div ng-app="myapp" ng-controller='myctrl'>
    <ul class="ul-list-10">
     <li ng-repeat="assetType in assetTypeList">
          <input type="checkbox" ng-model="assetType.checked" ng-click="fnChangeAssetType(assetType)" value="{{assetType.id}}" />
         {{assetType.id}}
     </li>
 </ul>
    </div>

jsFiddle For solution:http://jsfiddle.net/kLrvs4ty/1/

Shubham Nigam
  • 3,844
  • 19
  • 32