checkbox inside an a tag is not working

1,845 views
Skip to first unread message

AngularJSSufferer

unread,
Oct 3, 2013, 8:31:16 AM10/3/13
to ang...@googlegroups.com, aishwarya balachandran
Hi,

I have a checkbox and associated text inside an anchor tag as follows:

<a ng-click="change()">
  <input type="checkbox" ng-checked="content.active" ng-model="content.active">
  <div> click me! </div>
</a>

The value of content.active is getting binded properly, but the checkbox is always ticked (changes after the end of the change()).
Also, it works if i click on the text but not on the checkbox.

Help, somebody?

Thanks!

Vlada Janošević

unread,
Oct 3, 2013, 9:42:16 AM10/3/13
to ang...@googlegroups.com, aishwarya balachandran
<a ng-click="change()">
     <input type="checkbox" ng-checked="content.active" ng-model="content.active">
     <div> click me! </div>
</a>

What exactly do you want to do? Change  content.active  depending on checkbox?

AngularJSSufferer

unread,
Oct 3, 2013, 7:32:25 PM10/3/13
to ang...@googlegroups.com, aishwarya balachandran
http://plnkr.co/edit/ZAeJQvMef2C4kZpNsjf0

Try clicking on the checkbox, its always ticked even though the value has changed.

Please help.

Bryana Atanasova

unread,
Oct 3, 2013, 8:36:34 PM10/3/13
to ang...@googlegroups.com, aishwarya balachandran

OpenNota

unread,
Oct 6, 2013, 12:21:42 AM10/6/13
to ang...@googlegroups.com, aishwarya balachandran
When you click on the checkbox, angular changes content.active for you. And then you change it back to the status quo in the `change` function.

Ryan Randall

unread,
Oct 6, 2013, 1:15:48 PM10/6/13
to ang...@googlegroups.com, aishwarya balachandran
This example shows 3 different ways of interacting with content.active: direct, using a change function, and using a watch function: http://plnkr.co/edit/8OyTVTSh6IIOI0UdIRrR?p=preview

It uses different HTML, and so may not be useful in this case.

Chris Nicola

unread,
Oct 7, 2013, 10:26:27 AM10/7/13
to ang...@googlegroups.com, aishwarya balachandran
You basically have a checkbox with a label. The correct way to do this in HTML is to use <label for="checkbox-id"> as this already gives you a clickable label will change the checkbox when clicked. Then just use ng-change on the checkbox to trigger whatever code you want on the change.
Reply all
Reply to author
Forward
0 new messages