0

I'm having some static checkboxes and one checkbox use for "Check All" in HTML file. Then i want to check or un-check all of these checkbox when i click on the "Check All" checkbox. But i still not know where is approach of this stuff.

HTML code:

<div>
   <input type="checkbox" name="check_all" ng-model="formFruit.fruits.all" ng-true-value=":all:"/> Select All </br>
   <input type="checkbox" name="" ng-model="formFruit.fruits.apple" ng-true-value=":apple:"/> Apple </br>
   <input type="checkbox" name="" ng-model="formFruit.fruits.banana" ng-true-value=":banana:"/> Banana </br>
</div>

1 Answer 1

1

I am not sure, why you have different model names for each checkbox,you can reset it to false or clear those values as follows,

angular.forEach($scope.formFruit.fruits, function(furit) {        
    //sett it to false
});

or

$scope.formFruit.fruits = [];
Sign up to request clarification or add additional context in comments.

10 Comments

I have to make each of checkboxes with the different of model name because of i want to identity each of them and their value to check when i load edit form. So is that a bad way to do???
yeah, you should have single property with true/false only. check here stackoverflow.com/questions/26017286/…
I want to use specify value because when checkbox is checked and submit, server with concat all checked checkboxes to a string. For example if apple and banana are checked, server with have a string :apple::banaa:. So is that possible?
yes still its possible., you need to get the checked ones separately using loop and then create the string you want
Ah, so the problem that how the string will be handle to get the final string, right?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.