lundi 10 octobre 2016

Counting selected checkbox in AngularJS

I'm having a hard time counting selected checkboxes in my application. I've tried following along some other stack overflow questions but no dice yet...if you guys have any experience with counting checkboxes, some help would be great.

HTML:

<div class="row">
      <div class="col-md-12">
        <table id="document-table" st-table="documents" class="table">
         <div>Total checked: ()</div>
          <thead>
            <tr>
              <th>
                <st-select-all all="yourDisplayedCollection"></st-select-all>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat="document in documents">
              <td><input type="checkbox" ng-model="checkedDocument"/></td>
            </tr>
          </tbody>
         </table>
      </div>
    </div>

Controller:

$scope.selectAll = function (selected) {
        var documents = $scope.documents;
        angular.forEach(documents, function (documents) {
            documents.selected = selected;
        });
        // Update the counter
        if(selected){
            $scope.selectedCounter = documents.length;
        } else {
            $scope.selectedCounter = 0;
        }
    };

Thanks




Aucun commentaire:

Enregistrer un commentaire