function - Uncheck multiple groups of checkoxes in angularjs -


fiddle: https://jsfiddle.net/williamscott701/mzpdfjxv/3/

i have multiple groups of set of check boxes,

i need buttons uncheck groups of checkboxes (dynamically)

eg:

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

where the groups of checkboxes , b, each might have many checkboxes

but want same function used

html:

<div ng-controller="indexctrl">{{1+1}}   <h2>products</h2>   <div class="filters col-two">     <a ng-click="clearall()">clear 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 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 ;)

just add argument function.

  $scope.clearall = function(value) {     angular.foreach(value, function(color) {       color.selected = false;     });   }; 

Comments