I\'m trying to programatically set the value of Angular checkboxes to either, false
true
or indeterminate
. I understand that I cannot set
To make a checkbox indeterminated, you can use a directive
import { Directive, ElementRef,Input } from '@angular/core';
@Directive({ selector: '[indeterminate]' })
export class IndeterminateDirective {
@Input()
set indeterminate(value)
{
this.elem.nativeElement.indeterminate=value;
}
constructor(private elem: ElementRef) {
}
}
Then you're checkbox can be like
where
click(cliente: any) {
let indeterminated=(!cliente.checked && !cliente.indeterminated) ? true : false;
let checked=(!cliente.checked && cliente.indeterminated)?true:false
cliente.indeterminated = indeterminated;
cliente.checked=checked;
}
See that you have two variables "checked" and "indeterminated", you can make a cycle as you want