uglycode
uglycode

Reputation: 3082

AngularJS - unchecking checkbox

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.

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!

Upvotes: 1

Views: 462

Answers (1)

ThibaudL
ThibaudL

Reputation: 1009

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;
};

Upvotes: 3

Related Questions