I\'m trying to programatically set the value of Angular checkboxes to either, false
true
or indeterminate
. I understand that I cannot set
Yes, you can use [indeterminate]="condition"
(without any directives).
You can't do indeterminate="{{condition}}"
.
The difference is that [...]
sets property of the element, while without brackets you are setting attribute. HTMLInput element has property indeterminate
, but doesn't have such attribute.
In order use ngModel or FormControl, which holds simultaneously the both checked
and indeterminate
states, you should create a custom directive or/and additional logic in your primary component (for reference, see the answer from @Eliseo).
Q1. How can I cycle through these three state in the same way as you can with gmail?
Handle clicks, change state of the pair "checked" and "indeterminate" in cycle. Example with jQuery.
Q2. Why am I getting the ExpressionChangedAfterItHasBeenCheckedError with the current setup?
You have side effect in the checkedLabels
method, which changes state of the component, each time Angular checks value of the expression [indeterminate]="checkedLabels()"
.