How to find whether Checkbox is checked or not

Hi Team,

 We are using Ej1 Components with angular typescript.

I want to find the ejcheckbox whether is checked or not using typescript.

I used following code :

 var chkHObj = $("#chkHospital").data("ejCheckBox");
if (chkHObj.isChecked) {
                this.safetyInfo.HospitalAdmittance = true;
  }
            else {
                this.safetyInfo.HospitalAdmittance = false;
}

But it was not working.

Please help me on this .


Thanks,
Divakaran N




3 Replies

DL Deepa Loganathan Syncfusion Team October 9, 2018 06:28 AM UTC

Hi Divakar, 
 
 
Thanks for contacting Syncfusion Support. 
 
 
We have checked with your reported query on EJ Angular CheckBox to get the state of checkbox.  
You can get the Checkbox state in the following ways. 
 
 
1.      Using checkbox 'checked' API     
 
2.      Using checkbox isChecked Method 
 
3.      Using args.isChecked argument in change event 
 
 
 
We have prepared a sample to meet your requirement. Please download the sample from the below link. 
 
 
 
 
In this sample, we have created an instance of EJ CheckBox and accessed the checkstate API of checkbox in ngAfterViewInit() method. Also, the Checkstate can be accessed via change event of Checkbox in run time as highlighted below. 
 
 
[checkbox.component.html] 
 
<ej-checkbox id="Checkbox1" #Checkbox1 [(checked)]="checked" size="small" text="Music" (ejchange)="onChange($event)" ></ej-checkbox> 
 
 
 
[checkbox.component.ts] 
 
onChange(args) { 
        if (args.isChecked) { 
            alert("checkbox has been checked"); 
        } else { 
            alert("checkbox has been unchecked"); 
        } 
 
    } 
    ngAfterViewInit() { 
        if (this.checkBoxInstance.widget.element.ejCheckBox('checked')) { 
        alert("checkbox has been checked"); 
        } else { 
        alert("checkbox has been unchecked"); 
        } 
    } 
 
 
  
 
Also, check out the following links to explore further about Checkbox control. 
  
 
 
 
 
 
Please, let us know if you need any further assistance. 
 
 
Regards, 
 
Deepa L. 



DI divakar October 15, 2018 01:03 AM UTC

Hi Team ,  


Thanks for your Support . 

Its working for me.


Thanks,
Divakaran N


DL Deepa Loganathan Syncfusion Team October 15, 2018 01:06 PM UTC

Hi Divakar,  
 
Most welcome. Please let us know if you have any further queries. 
 
Regards,  
 
Deepa L. 


Loader.
Up arrow icon