Angular UI Components Documentation
The Angular RadioButton lets users make one choice among a set of mutually exclusive, related options. This guide adds the Angular RadioButton (jqxRadioButton) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxradiobutton 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 jqxRadioButtonModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxRadioButtonModule } from 'jqwidgets-ng/jqxradiobutton';
@Component({
selector: 'app-root',
imports: [jqxRadioButtonModule],
templateUrl: './app.html'
})
export class App {}
The source of the live RadioButton demo.
<h3>
House Contract
</h3>
<jqxRadioButton (onChange)="firstBtnOnChange($event)"
[width]="250" [height]="25" [checked]="true">
<span>12 Months Contract</span>
</jqxRadioButton>
<jqxRadioButton (onChange)="secondBtnOnChange($event)"
[width]="250" [height]="25">
<span>6 Months Contract</span>
</jqxRadioButton>
<jqxRadioButton (onChange)="thirdBtnOnChange($event)"
[width]="250" [height]="25">
<span>3 Months Contract</span>
</jqxRadioButton>
<jqxRadioButton
[width]="250" [height]="25" [disabled]="true">
<span>1 Month Contract</span>
</jqxRadioButton>
<div style="margin-top: 10px">
<div>Events:</div>
<div #events></div>
</div>
import { Component, ElementRef, viewChild } from '@angular/core';
import { CommonModule } from '@angular/common';
import { jqxRadioButtonModule } from 'jqwidgets-ng/jqxradiobutton';
@Component({
imports: [CommonModule, jqxRadioButtonModule],
selector: 'app-root',
templateUrl: './app.html'
})
export class App {
readonly eventsLog = viewChild.required<ElementRef>('events');
count = 0;
clearLog(): void {
this.count++;
let log = this.eventsLog().nativeElement;
if (this.count >= 2) {
log.innerHTML = '';
this.count = 0;
}
}
firstBtnOnChange(event: any): void {
if (this.eventsLog()) {
this.clearLog();
let log = this.eventsLog().nativeElement;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 12 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 12 Months Contract</span></div>';
}
}
}
secondBtnOnChange(event: any): void {
if (this.eventsLog()) {
this.clearLog();
let log = this.eventsLog().nativeElement;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 6 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 6 Months Contract</span></div>';
}
}
}
thirdBtnOnChange(event: any): void {
if (this.eventsLog()) {
this.clearLog();
let log = this.eventsLog().nativeElement;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 3 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 3 Months Contract</span></div>';
}
}
}
}
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 Radio Button's state changes from one state to another.
<jqxRadioButton (onChange)="onChange($event)"></jqxRadioButton>
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.
<jqxRadioButton #myRadioButton></jqxRadioButton>
import { Component, viewChild } from '@angular/core';
import { jqxRadioButtonModule, jqxRadioButtonComponent } from 'jqwidgets-ng/jqxradiobutton';
@Component({
selector: 'app-root',
imports: [jqxRadioButtonModule],
templateUrl: './app.html'
})
export class App {
readonly myRadioButton = viewChild.required<jqxRadioButtonComponent>('myRadioButton');
run(): void {
const value = this.myRadioButton().val();
console.log(value);
}
}