0

I have this code:

<input type="checkbox" ng-checked="item.selected == 'yes'"  ng-click="change()">{{item.selected}}<br/>

http://jsfiddle.net/NmQXp/2/

As you can see, there are three identical checkboxes, with their checked status binded to the value of some string. The catch is that I want to introduce an intermediate "partially selected" state to the checkboxes. In fact what I want to do is use the checkbox to change the value from "pending" to "ongoing" and then to "done" (I'm making a ToDo list).

If you click one of them several times you can see the correct behavior in the others, but the checked status is wrong in the one you are clicking.

¿Is this a bug in Angular Binding, or am I missing something?

1 Answer 1

2

Well i tried to fix your fiddle to take care of the checked issue. The behavior was inconsistent because checkbox gets checked when mouse is clicked over it due to the default HTML behavior. I added these lines to prevent the default behavior for checkbox.

 if ($scope.item.selected == 'no') {
            $scope.item.selected = 'halfway';
            $event.preventDefault();
        }

Here is the updated fiddle.

http://jsfiddle.net/cmyworld/J27jN/

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

3 Comments

Thanks! I didn't know you could pass the event as a parameter.
I can't find this $event wrapper for the event anywhere in the documentation. Where did you get it from? And what other variables have we available inside angular expressions? Is there a list of them?
Well i don't remember, but it was definitely not from the documentation. Most probably from some old SO question :)

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.