Angular Get Selected CheckBoxes

心已入冬 提交于 2019-12-01 02:30:20

here is the implemented plunker

 <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}}

 $scope.ShowSelected = function() {
  console.log($scope.selected);
  alert(JSON.stringify($scope.selected));
};

You can use the ng-model directive to directly bind a property to the element.

e.g.

<input type="checkbox" ng-model="X.Item.Id" />

This will update your model.

From this you will be able just to check the values within your model and see which are checked.

e.g.

angular.forEach($scope.yourModelItems, function(item){
    // item.value ? 0 : 1;
});

Check out the documentation for ngModel. Also the ToDo list example on the angularjs.org homepage demonstrates this.

p.s. On a side note, you can also make your angular directives html5 friendly by adding data- before. e.g. data-ng-model="X.Item.Id"

<tr ng-repeat="x in numbers" >
<td><input type="checkbox"  ng-model="selected[x.id]"></td>`<tr ng-repeat="x in numbers" >

then button for action

 <button ng-click="get_all_cheked()">Get checked</button>    

and then in controller

 $scope.selected = {};
 $scope.get_all_cheked=function () {
 console.log("click");
 console.log($scope.selected);
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!