dimanche 24 janvier 2016

Uncheck multiple groups of checkoxes in angularjs

fiddle: http://ift.tt/1ZL1omc

i have multiple groups of set of check boxes,

i need buttons to uncheck the groups of checkboxes (dynamically)

eg:

ng-click="clear(a)";
ng-click="clear(b)";

where as the the groups of checkboxes are a and b, each might have many checkboxes

but i want the same function to be used

HTML:

<div ng-controller="IndexCtrl">{{1+1}}
  <h2>Products</h2>
  <div class="filters col-two">
    <a ng-click="clearAll()">Clear all filters</a>
    <h3>Color</h3>
    <div ng-repeat="color in colors">
      {{ color.name }}
      <input type="checkbox" ng-model="color.selected">
    </div>
  </div>
  {{colors}}
  <br>
  <br>
  <br>
  <a ng-click="clearAll(a)">Clear all filters</a>
  <h3>Color</h3>
  <div ng-repeat="colora in colorsa">
    {{ colora.name }}
    <input type="checkbox" ng-model="colora.selected">
  </div>
  {{colorsa}}
</div>

angular:

var app = angular.module('myApp', []);
app.controller('IndexCtrl', ['$scope', function($scope) {
  $scope.colors = [{
    id: 1,
    name: "Blue"
  }, {
    id: 2,
    name: "Green"
  }, {
    id: 3,

  }];    name: "Red"
  $scope.colorsa = [{
    id: 1,
    name: "Blue"
  }, {
    id: 2,
    name: "Green"
  }, {
    id: 3,
    name: "Red"
  }];
  $scope.color_ids = [];

  $scope.clearAll = function() {
    angular.forEach($scope.colors, function(color) {
      color.selected = false;
    });
  };
}]);

i'm no expert in angularjs so, go easy on me ;)




Aucun commentaire:

Enregistrer un commentaire