Is there a way to create an ng-click function that will only execute after the value of the ng-model in a scope variable changes? In my scenario, I have a list of analysis
objects within a list called analyses
, each with an include
boolean attribute used for toggling inclusion/exclusion. These objects are displayed as button checkboxes in HTML.
This is the HTML code snippet:
Number of bisulfite sequences: {{included}} used / {{excluded}} excluded
<div ng-repeat="analysis in analyses"><br><label class="btn btn-success"
ng-model="analysis.include" ng-click="set(analysis.include)" btn-checkbox>
Here's the corresponding controller code:
$scope.analyses = some_list_of_analyses
$scope.included = 0
$scope.excluded = $scope.analyses.length
$scope.set = function(include){
//additional logic involving $scope.analyses
if(include){
$scope.included += 1
$scope.excluded -= 1
}
else{
$scope.excluded += 1
$scope.included -= 1
}
}
Currently, when starting with all analyses excluded (as set during initialization), clicking a button results in incorrect values being displayed (-1 used / n+1 excluded) because ng-click triggers before the variable update. Are there any alternatives to make ng-click wait until variables are bound or to modify $scope.analyses directly within the ng-click method?
I appreciate any suggestions!
EDIT: The ng-model statement is required for the btn-checkbox directive, which presents a toggle for including/excluding analyses. Any advice on alternative directives or CSS implementations for indicating inclusion/exclusion would be helpful!