0

so far I've only seen people used ng-model to bind the state of checkbox. How can I know which checkbox is checked with angularjs? for example I want to get the index of the checked checkedbox so that I can do something on the backend.

If it were in jquery / js I can use function to catch the state of the checkbox and send the index or etc info to be send back to database.

my plunker : http://plnkr.co/edit/dG9cwswiVzLdjEnpSNvu?p=preview

3
  • 1
    It looks like you have used properly. what you exactly want to do? Commented Apr 4, 2014 at 10:17
  • If checkbox is checked item.done will be true, Is it not good enough? Commented Apr 4, 2014 at 10:18
  • @JayShukla it's just some css, what if I want to run some function? for example grab the name of the checked checkbox? I need those data to be passed to the backend. Commented Apr 4, 2014 at 10:18

2 Answers 2

1

You could use ng-click, like this:

http://plnkr.co/edit/kOTtbSHbw1kaGWmjqQbf?p=preview

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

5 Comments

lol this is so simple, thx.. I thought of passing param with ng-model which is stupid
can I pass multiple param? like ng-click="boxChecked({{groupId}},$index)"
Yes you can. I misunderstood your problem. :)
you don't need the {{ }}, so just try but ng-click="boxChecked(groupId,$index)
actually it's like this : item.groupId , that's why I put {{}}
1

I am not clear about your problem but if you want label which associate with checkbox then you should use ng-init.

<div ng-controller="main">
    <div class="checkbox" ng-repeat="item in items">
         <input type="checkbox" id="{{$index}}" ng-model="item.done"><label for="{{$index}}" class="done-{{item.done}}" ng-init="item.text='Label for' + item.val">Label for {{item.val}}</label>
    </div>
    {{items}}
</div>

See Demo

1 Comment

thanks for pointing out that Jay. how to pass multiple param like this ng-click="boxChecked({{groupId}},$index)" ??

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.