title: angularjs checkbox validation at least two
body: <p>Using AngularJS, I want to establish a validation rule where at least 2 check boxes must be checked for the input to be considered valid. I have tried this:</p>
  
  <pre><code>&lt;div ng-repeat="item in items"&gt;
                              &lt;label&gt;&lt;input type="checkbox" ng-model="checked[item.id]" ng-required="!isChecked" /&gt;
                              &lt;span&gt;{{item.title}}&lt;/span&gt;&lt;/label&gt;
                            &lt;/div&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// checkbox validation
      angular.module('app', []).
  
      run(function($rootScope) {
          $rootScope.items = [
              { id: 1, title: 'Certified Plumber' },
              { id: 2, title: 'Carpentry Experience' },
              { id: 3, title: 'Certified Electrician' },
              { id: 4, title: 'Bartending Experience' },
              { id: 5, title: 'Food Hygiene Certificate' },
              { id: 6, title: 'First Aid Course' },
              { id: 7, title: 'Forklift Drive Certificate' },
              { id: 8, title: "Driver's License (Type B)" }
          ];
          $rootScope.checked = {};
          $rootScope.isChecked = false;
          $rootScope.$watch('checked', function(selected) {
              $rootScope.isChecked = false;
              angular.forEach(selected, function(isChecked) {
                  if (isChecked) $rootScope.isChecked = true;
              });
          }, true);
      });
  </code></pre>
  
  <p>Now the validation is working when at least one checkbox is checked. How do I customize it for at least two checkboxes?</p>