all files / app/main/components/material-docs/demo-partials/checkbox/demoSelectAll/ script.js

5.26% Statements 1/19
0% Branches 0/10
0% Functions 0/6
5.26% Lines 1/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                                                                         
 
angular.module('checkboxDemo3', ['ngMaterial'])
 
.controller('AppCtrl', function($scope) {
  $scope.items = [1,2,3,4,5];
  $scope.selected = [1];
  $scope.toggle = function (item, list) {
    var idx = list.indexOf(item);
    if (idx > -1) {
      list.splice(idx, 1);
    }
    else {
      list.push(item);
    }
  };
 
  $scope.exists = function (item, list) {
    return list.indexOf(item) > -1;
  };
 
  $scope.isIndeterminate = function() {
    return ($scope.selected.length !== 0 &&
        $scope.selected.length !== $scope.items.length);
  };
 
  $scope.isChecked = function() {
    return $scope.selected.length === $scope.items.length;
  };
 
  $scope.toggleAll = function() {
    if ($scope.selected.length === $scope.items.length) {
      $scope.selected = [];
    } else if ($scope.selected.length === 0 || $scope.selected.length > 0) {
      $scope.selected = $scope.items.slice(0);
    }
  };
});