vendredi 6 mai 2016

ng-repeat loop on checkboxes

  <span  ng-repeat="s  in colors">
         <p><li><input type="checkbox"   ng-model="colors[id].checked"   ng-change="setColor(s.id)"> &nbsp; </li></p> 
</span> 

In my controller,

$scope.colorsel= []; 
    $scope.setColor = function(a){
         if($scope.colorsel.indexOf(a) == -1 ){
              $scope.colorsel.push(a);
         }
         else{
             var index =  $scope.colorsel.indexOf(a)
            $scope.colorsel.splice(index,1);

         }
    }

Am getting the colorsel values correctly. But if i select one checkbox, it is just showing that all checkboxes are selected(means tick mark appears in all checkboxes but it is taking only the id of the check box which is selected in colorsel array). I f I select other one, all the tick marks will disappear. Plz help me to solve this.




Aucun commentaire:

Enregistrer un commentaire