{"id":54,"date":"2018-08-18T03:11:00","date_gmt":"2018-08-18T03:11:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/08\/18\/how-to-get-selected-checkboxes-using-angularjs\/"},"modified":"2020-08-22T14:04:51","modified_gmt":"2020-08-22T12:04:51","slug":"how-to-get-selected-checkboxes-using-angularjs","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/how-to-get-selected-checkboxes-using-angularjs\/","title":{"rendered":"How to Get Selected CheckBoxes Using AngularJs"},"content":{"rendered":"<p>In this blog, I would teach you two ways to get a list of selelected checkboxes using AngularJS with the click on a button. In another blog we would explain how to perform an action when a checkbox is checked (ng-change or ng-click event).<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><b>HTML<\/b><br \/>\nFor the two methods, the html code remains the same as below:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;div<\/span> <span style=\"color: #0000cc;\">ng-repeat=<\/span><span style=\"background-color: #fff0f0;\">\"row in Skills\"<\/span> <span style=\"color: #007700;\">&gt;<\/span>\r\n <span style=\"color: #007700;\">&lt;label&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;input<\/span> <span style=\"color: #0000cc;\">type=<\/span><span style=\"background-color: #fff0f0;\">\"checkbox\"<\/span> <span style=\"color: #0000cc;\">ng-model=<\/span><span style=\"background-color: #fff0f0;\">\"row.selected\"<\/span> <span style=\"color: #007700;\">&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;span&gt;<\/span> {{row.Skill}} <span style=\"color: #007700;\">&lt;\/span&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/label&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/div&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;button<\/span> <span style=\"color: #0000cc;\">ng-click=<\/span><span style=\"background-color: #fff0f0;\">\"GetSelected()\"<\/span><span style=\"color: #007700;\">&gt;<\/span>Get Selected<span style=\"color: #007700;\">&lt;\/button&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><b>AngularJS (Script 1)<\/b><\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">$scope.selected <span style=\"color: #333333;\">=<\/span> {};\r\n$scope.DeleteSelected<span style=\"color: #333333;\">=<\/span><span style=\"color: #008800; font-weight: bold;\">function<\/span> () {               \r\n        angular.forEach($scope.selected, <span style=\"color: #008800; font-weight: bold;\">function<\/span>(value, key) {\r\n console.log(key);\r\n console.log(value);   \r\n });\r\n};\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><b>AngularJS (Script 2)<\/b><br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%\">$scope.GetSelected<span style=\"color: #333333\">=<\/span><span style=\"color: #008800; font-weight: bold\">function<\/span>() {       \r\n   <span style=\"color: #008800; font-weight: bold\">var<\/span> selected <span style=\"color: #333333\">=<\/span> [];\r\n   angular.forEach($scope.Skills, <span style=\"color: #008800; font-weight: bold\">function<\/span>(row) {\r\n   <span style=\"color: #008800; font-weight: bold\">if<\/span> (row.selected) {          \r\n  console.log(row.ID);\r\n  console.log(row.Skill);\r\n   }\r\n   });\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Both methods have been tested by me and works very fine. You could reach me by comment below if you have any challenge using the code.<\/p>\n<p>&nbsp;<\/p>\n<p>Thanks for learning.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, I would teach you two ways to get a list of selelected checkboxes using AngularJS with the click on a button. In &hellip; <\/p>\n","protected":false},"author":1,"featured_media":512,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[113],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angularjs"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":2,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media\/512"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}