I am fetching my data from Json tables in form of list.The submit button should be enabled only when all the check boxes are checked. this is my code. Html:
<ol>
<li ng-repeat='box in Box.json' id='box' >
<input type="checkbox" value='{{box.id}}'>{{box.name}}</li>
</ol>
//Javascript:
$scope.check=function(){
return ($scope.check1 && $scope.check2 && $scope.check3)
}
The above scope variables are ng-models of each
Output
I'd just adjust your box object directly and then reduce your array of objects to a boolean value to see if all the checkboxes are checked.
<ol>
<li ng-repeat='box in Box.json' id='box'>
<input type="checkbox" ng-model="box.checked"> {{box.name}}
</li>
</ol>
And your check function.
$scope.check=function(){
return $scope.Box.json.reduce(function(prev,value){
if(!prev) return false;
return value.checked && true || false;
},true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With