Angular UI Components Documentation
The Angular CheckBox displays a check box that allows the end-user to select a true, false or indeterminate condition. This guide adds the Angular CheckBox (jqxCheckBox) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxcheckbox In an Angular project (to start one, see Getting started with Angular), add the package with the Angular CLI. It asks for a theme and adds the styles to angular.json:
ng add jqwidgets-ng
Components are standalone: add jqxCheckBoxModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
@Component({
selector: 'app-root',
imports: [jqxCheckBoxModule],
templateUrl: './app.html'
})
export class App {}
The source of the live CheckBox demo.
<div style='font-family: Verdana Arial; font-size: 12px; width: 400px;'>
<div style='float: left; width: 400px;'>
<h3 style='margin-left: 15px;'>Categories</h3>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
Entertainment
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25' [checked]='true'>
<span>Computers</span>
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
<span>Sports</span>
</jqxCheckBox>
</div>
<div style='float: left; width: 400px; margin-top: 10px;'>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
Health
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
<span>Finance</span>
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
<span>Travel</span>
</jqxCheckBox>
</div>
<div style='float: left; width: 400px; margin-top: 10px;'>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
Music
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
<span>Technology</span>
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25'>
<span>Publishing</span>
</jqxCheckBox>
</div>
<br />
<div style='float: left; width: 400px; margin-top: 10px;'>
<h3 style='margin-left: 15px;'>States</h3>
<jqxCheckBox (onChange)="checkBox10OnChange($event)" style='margin-left: 10px; float: left;'
[width]='120' [height]='25' [checked]='true'>
<span #span10>Checked</span>
</jqxCheckBox>
<jqxCheckBox (onChange)="checkBox11OnChange($event)" style='margin-left: 10px; float: left;'
[width]='120' [height]='25' [checked]='false'>
<span #span11>Unchecked</span>
</jqxCheckBox>
</div>
<div style='float: left; width: 400px; margin-top: 10px;'>
<jqxCheckBox (onChange)="checkBox12OnChange($event)" style='margin-left: 10px; float: left;'
[width]='120' [height]='25' [hasThreeStates]='true' [checked]='null'>
<span #span12>Indeterminate</span>
</jqxCheckBox>
<jqxCheckBox style='margin-left: 10px; float: left;'
[width]='120' [height]='25' [disabled]='true'>
<span>Disabled</span>
</jqxCheckBox>
</div>
</div>
import { Component, ElementRef, viewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
@Component({
imports: [CommonModule, jqxCheckBoxModule],
selector: 'app-root',
templateUrl: './app.html'
})
export class App {
readonly span10 = viewChild.required<ElementRef>('span10');
readonly span11 = viewChild.required<ElementRef>('span11');
readonly span12 = viewChild.required<ElementRef>('span12');
checkBox10OnChange(event: any): void {
let checked = event.args.checked;
if (checked) {
this.span10().nativeElement.innerHTML = 'Checked';
} else {
this.span10().nativeElement.innerHTML = 'Unchecked';
}
}
checkBox11OnChange(event: any): void {
let checked = event.args.checked;
if (checked) {
this.span11().nativeElement.innerHTML = 'Checked';
} else {
this.span11().nativeElement.innerHTML = 'Unchecked';
}
}
checkBox12OnChange(event: any): void {
let checked = event.args.checked;
if (checked) {
this.span12().nativeElement.innerHTML = 'Checked';
} else if (false == checked) {
this.span12().nativeElement.innerHTML = 'Unchecked';
} else {
this.span12().nativeElement.innerHTML = 'Indeterminate';
}
}
}
Options are inputs, bound with [name]="value".
Events are outputs named on plus the event name with a capital first letter. For example, change: This is triggered when the checkbox's state changes from one state to another.
<jqxCheckBox (onChange)="onChange($event)"></jqxCheckBox>
onChange(event: any): void {
console.log(event.args);
}
Get the component with a signal query and call its methods. For example, val: Sets or gets the value.
<jqxCheckBox #myCheckBox></jqxCheckBox>
import { Component, viewChild } from '@angular/core';
import { jqxCheckBoxModule, jqxCheckBoxComponent } from 'jqwidgets-ng/jqxcheckbox';
@Component({
selector: 'app-root',
imports: [jqxCheckBoxModule],
templateUrl: './app.html'
})
export class App {
readonly myCheckBox = viewChild.required<jqxCheckBoxComponent>('myCheckBox');
run(): void {
const value = this.myCheckBox().val();
console.log(value);
}
}