Tagged: pass checkbox value to controller angularjs

Get all checked Checkbox Values in AngularJS 0

Get all checked Checkbox Values in AngularJS

Get all checked Checkbox Values in AngularJS

In this Post We Will Explain About is Get all checked Checkbox Values in AngularJS With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to arrays – How to get checkbox value in angularjs Example

In this post we will show you Best way to implement angularjs – How to get the selected check box value, hear for how to get ng repeat checkbox values on submit function in angularjs with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Include External Libs

<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js'></script>  
<link rel='stylesheet prefetch' href='https://netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css'>

index.html

<body ng-app="liveApp" ng-controller="liveCtrl">
<h1>AngularJS Checkboxes Bound to Target Array with Initial Selections Checked</h1>
  <div class="panel panel-primary">
    <div class="panel-heading">
      <h3 class="panel-title">{{title}}</h3>
    </div>
    <div class="panel-body">
      <h3>Angularjs Checkboxes Example</h3>
      <p>
        Live24u is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.
        <ul>
          <li>You are Most welcome in my youtube Channel ::  <strong>SOLVED</strong></li>
          <li>We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. ::  <strong>SOLVED</strong></li>
        </ul>
      </p>

      <p ng-repeat="student in liveDataList" class="student" id="{{student.id}}">
      {{student.id}} <input type="checkbox" ng-change="get_stud(bool, student)" ng-model="bool" ng-checked="isChecked(student.id)"> Click this to all the student get_stud this student data with the target array.  {{student}} Selected: {{bool}} 

      <h3>angular Final Data Array</h3>
      <pre>{{data | json}}</pre>

      <h3>All Checkboxes Array in angular</h3>
      <pre>{{liveDataList | json}}</pre>

    </div>
  </div>  
</body>

index.js

var lb = "• "; // used for console.log()
var liveApp = angular.module("liveApp", []);

liveApp.controller('liveCtrl', function($scope) {
  $scope.title = 'AngularJS Checkboxes Bound to Target Array with Initial Selections Checked';
  $scope.content = '';

  $scope.isChecked = function(id){
      var same = false;
      for(var i=0 ; i < $scope.data.length; i++) {
        if($scope.data[i].id == id){
          same = true;
        }
      }
      return same;
  };
  
  $scope.liveDataList = [
    {
      "id": "1",
      "data": "jaydeep Gondaliya",
    },
    {
      "id": "2",
      "data": "Ankit kathiriya",
    },
    {
      "id": "3",
      "data": "krunal sisodiya",
    },
  ];
    
  $scope.data = [
    {
      "id": "1",
      "data": "jaydeep Gondaliya",
    },
    {
      "id": "3",
      "data": "krunal sisodiya",
    },
  ];

  $scope.get_stud = function(bool, student){
    if(bool){
      // add student
      $scope.data.push(student);
    } else {
      // remove student
      for(var i=0 ; i < $scope.data.length; i++) {
        if($scope.data[i].id == student.id){
          $scope.data.splice(i,1);
        }
      }      
    }
  };
  
});

style.css

.panel {
  width:95%;
  margin:2em auto;
}

get all checked checkbox value in angularjs

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Get all checked Checkbox Values in AngularJS And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.