1

I'm using angularjs as much as possible - I'm editing some legacy system and I cannot afford to change too much. So, basically, I need to implement a function that unchecks every checkbox in the page. The easiest solution - without changing too much of the existing system - was to use angular.element. Now I know, this is a REALLY bad solution, but I need to make it work.

Currently, it works (visually at least), since every checkbox gets unchecked, however, on another click the checkbox doesn't work - it needs to be pressed twice, before being activated again.

Here's a demo of how things are and how I've implemented a partial solution: http://jsbin.com/xicubegira/1/edit?html,js,output Use case is as follows.

  • Click on checkbox - the counter will increment to 1, checkbox will become checked
  • Click on checkbox again - the counter will increment to 2, checkbox will become unchecked
  • Click on checkbox - the counter will increment to 3, checkbox will become checked
  • Press the 'uncheck me' button - the counter will not increment, checkbox will become unchecked (which is OK)
  • Click on checkbox again - the checkbox becomes 'checked', but the counter is not incremented!

So, how could I uncheck all checkboxes in the page and still maintain initial functionality? I'm guessing the issue here is, that nothing changes in scope of checkbox, so ng-change doesn't get fired.

Thanks for your help!

1 Answer 1

3

Your issue here is that you'r not changing your model so ng-change cannot be called since the data hasn't change.
Can't you do a simple set to false of your model :

$scope.uncheck = function(){        
    $scope.confirmed = false;
};
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that did the trick. Didn't even have to use angular.element, perfect!

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.