4

I have some checkboxes in HTML:

<input type="checkbox" name="type[]" value="3">
<input type="checkbox" name="type[]" value="4">
<input type="checkbox" name="type[]" value="5">

How I can get all selected values in Angular JS?

I tried to add for earch input: ng-model="type[]"

3
  • How do you generate the checkboxes? Commented Apr 20, 2015 at 12:42
  • It has been already answered to this question here: stackoverflow.com/questions/14514461/… Commented Apr 20, 2015 at 12:43
  • Checkboxes are genetated in JS/Jquery - plugin bootstrap-checkboxes Commented Apr 20, 2015 at 12:55

1 Answer 1

1

Try this:

<div ng-controller="MyCheckbox" 
 ng-init="checkboxes = {1: true, 2: false, 3: true, 4: false}">
    <input type="checkbox" ng-model="checkboxes.1">1
    <input type="checkbox" ng-model="checkboxes.2">2
    <input type="checkbox" ng-model="checkboxes.3">3
    <input type="checkbox" ng-model="checkboxes.4">4
    <br>{{checkboxes}}
</div>

JSFIDDLE DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

How to do name for chekboxes? That in server I have: type[] = 1, type[] = 2
Why do you need the names for? And what you "have on server" is quite confusing.
How I will to prepare data in server if these have not name, for example $_POST['type'][]?

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.