Hello syncfusion team,
I am trying to set the checked state of a syncfusion checkbox, but without a ViewChild because in my scenario, I don't have a ViewChild available, where I want to achieve the state change. I tried to use basic HTML and document.getElementById(), so:
1) (document.getElementById('ejsCheckbox') as HTMLInputElement).checked = true;
or
2) (document.getElementById('ejsCheckbox') as any).checked = true;
but neither worked. Here is a stackblitz to clarify this problem: https://stackblitz.com/edit/angular-4y69mm?file=src%2Fapp%2Fapp.component.ts
Thanks in regard,
Jonas Czeslik
|
import { getComponent } from '@syncfusion/ej2-base';
turnOnWithHTML() {
let checkboxed: CheckBox = getComponent(
document.getElementsByClassName('e-checkbox')[0],
'checkbox'
) as CheckBox;
checkboxed.checked = true;
console.log(checkboxed.checked);
} |
I modified it a little bit because I wanted to get a checkbox based on its id and not based on the general class name and its index, which would not work in a dynamic scenario.
Problem is that I could not only say
|
turnOnWithHTML() {
let CheckboxELem: any = document
.getElementById('ejsCheckbox')
.querySelector('input');
let checkboxed: CheckBox = CheckboxELem.ej2_instances[0];
checkboxed.checked = true;
console.log(checkboxed.checked);
}
|