I'm quite new to the superheroic framework AngularJS, so please excuse my noobness! So, while I was trying to develop a simple SPA that allowed admins to change permissions of other users in my website through a table filled with selection checkboxes, I came by an issue. I defined $scope.checked
so I could know how many users the administrator chose and also $scope.mainCheckBox
which would hold the correct CSS class for the major checkbox (like the one from Gmail, which you use to select all/none) in each of the three situations: all users selected, no users selected and partial selection. This simple logic goes as follows:
$scope.updateMainCheckBox = function(){
if(this.checked==this.users.length) this.mainCheckBox = "qm-icon-checked";
else if(!this.checked) this.mainCheckBox = "";
else this.mainCheckBox = "qm-icon-minus";
};
Running this at the end of the ng-click event callback of the other checkboxes, this code was capable of choosing the class correctly but it wouldn't assign the class to the mainCheckBox
. When I changed every this.mainCheckBox
to $scope.mainCheckBox
it all went well and the page would behave as expected.
So, I know in vanilla Js this
is a reference to the window
object but since AngularJS has its own event handling loop, I believe that's not the case now. I expected it to be a ref to $scope
, since checked
and users
were found, but apparently it's not. So, what's happening here? And also, is there a more "angular" way to implement this?