samedi 19 novembre 2016

Get the value of all checkbox when checkall checkbox is checked

pic I'am new to angularjs, I'm creating an application of attendance. When i check the checkall checkbox all the checkbox of name is also check and What i really wanted to achieve is to get the value of checked checkboxes. I'm done with checking all checkboxes. I just want to store all the value of checkboxes in an array. I can only get data when i check those checkboxes one by one. Thank you in advance.

In my html here is my code.

         <ion-checkbox ng-model="Selected" ng-click="checkAll()">
         <div class="wew">
         Check All Checkbox
         </div></ion-checkbox>
         </label></div>
         <table><tr><th><center>
         List of Names
         </center></th>
         <th colspan="3">
         Actions
        </th></tr><tr><td><label>
        <ion-checkbox ng-repeat="role in roles" ng-model="isChecked" ng- 
         change="format(isChecked,role,$index)"><div class="wew">
         
         </div></ion-checkbox>
         </label></td>

And in my controllers code. First this is my code where i get the list of names.

         $http.post(link1, {section: section}).success(function(attendance){
         for(a = 0; a<attendance.length; a++){
          $scope.roles = [
          attendance[0].Full_Name,
          attendance[1].Full_Name,
          attendance[2].Full_Name,
          attendance[3].Full_Name,
          attendance[4].Full_Name,
          attendance[5].Full_Name,
          attendance[6].Full_Name,
          attendance[7].Full_Name,
          attendance[8].Full_Name,
          attendance[9].Full_Name,
          ]
          }
          })
          .error(function(err) {
         console.log(err)
          })

And this is my code where i wanted to execute the checkall and automatically store the data in $scope.selected = []; if i click the check all checkbox..

      $scope.checkAll = function () {
      if ($scope.Selected) {
        $scope.Selected = false;
       } else {
        $scope.Selected = true;
        }
       $scope.isChecked= $scope.Selected;


      $scope.selected = [];
       $scope.format = function (isChecked, role, $index) {
        if (isChecked == true) {
         $scope.selected.push(role);
         }
        else {
        var _index = $scope.selected.indexOf(role);
        $scope.selected.splice(_index, 1);
        }
        var students = $scope.selected;
        console.log(students);
        }
        }




Aucun commentaire:

Enregistrer un commentaire