Angular UI Components Documentation
The Angular Slider represents a flexible Slider that lets the user select from a range of values by moving a thumb along a track. This guide adds the Angular Slider (jqxSlider) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxslider 
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 jqxSliderModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxSliderModule } from 'jqwidgets-ng/jqxslider';
@Component({
selector: 'app-root',
imports: [jqxSliderModule],
templateUrl: './app.html'
})
export class App {}
The source of the live Default Functionality demo.
<div style="width: 550px">
<div style="height: 180px;">
<div style="float: left">
<span style="font-style: italic;">Red</span>
<jqxSlider #redSlider (onChange)='redSliderOnChange()'
[height]='60' [min]='0' [max]='255' [tickLabelFormatFunction]='tickLabelFormatFunction'
[value]='0' [step]='25.5' [mode]='"fixed"' [tooltipFormatFunction]='tooltipFormatFunction'
[showTickLabels]='true' [tooltip]='true' [ticksFrequency]='25.5'>
</jqxSlider>
<span style="font-style: italic;">Green</span>
<jqxSlider #greenSlider (onChange)='greenSliderOnChange()'
[height]='60' [min]='0' [max]='255' [tickLabelFormatFunction]='tickLabelFormatFunction'
[value]='0' [step]='25.5' [mode]='"fixed"' [tooltipFormatFunction]='tooltipFormatFunction'
[showTickLabels]='true' [tooltip]='true' [ticksFrequency]='25.5'>
</jqxSlider>
<span style="font-style: italic;">Blue</span>
<jqxSlider #blueSlider (onChange)='blueSliderOnChange()'
[height]='60' [min]='0' [max]='255' [tickLabelFormatFunction]='tickLabelFormatFunction'
[value]='255' [step]='25.5' [mode]='"fixed"' [tooltipFormatFunction]='tooltipFormatFunction'
[showTickLabels]='true' [tooltip]='true' [ticksFrequency]='25.5'>
</jqxSlider>
</div>
<div class="jqx-rc-all colorBlock" id="colorBlock">
<div id="colorLabel"></div>
</div>
</div>
<jqxCheckBox (onChange)='checkBoxOnChange($event)'
[width]='200' [checked]='false'>
Smooth Thumb Drag
</jqxCheckBox>
</div>
import { Component, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxSliderComponent } from 'jqwidgets-ng/jqxslider';
import { CommonModule } from '@angular/common';
import { jqxSliderModule } from 'jqwidgets-ng/jqxslider';
import { jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
@Component({
imports: [CommonModule, jqxSliderModule, jqxCheckBoxModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App {
readonly redSlider = viewChild.required<jqxSliderComponent>('redSlider');
readonly greenSlider = viewChild.required<jqxSliderComponent>('greenSlider');
readonly blueSlider = viewChild.required<jqxSliderComponent>('blueSlider');
ngAfterViewInit(): void {
this.setColor();
}
redSliderOnChange(): void {
this.setColor();
}
greenSliderOnChange(): void {
this.setColor();
}
blueSliderOnChange(): void {
this.setColor();
}
checkBoxOnChange(event: any): void {
let checked = event.args.checked;
let value = 'default';
if (!checked) {
value = 'fixed';
}
this.redSlider().mode(value);
this.greenSlider().mode(value);
this.blueSlider().mode(value);
}
setColor(): void {
let red = this.fixHex(Math.round(this.redSlider().value()).toString(16)),
green = this.fixHex(Math.round(this.greenSlider().value()).toString(16)),
blue = this.fixHex(Math.round(this.blueSlider().value()).toString(16));
document.getElementById('colorBlock')!.style.backgroundColor = '#' + red + green + blue;
document.getElementById('colorLabel')!.innerHTML = ('#' + red + green + blue).toUpperCase();
let color = this.getTextElement({
r: parseInt(red, 16),
g: parseInt(green, 16),
b: parseInt(blue, 16)
});
document.getElementById('colorLabel')!.style.color = color;
}
fixHex(hex: any): any {
return hex.length < 2 ? '0' + hex : hex;
}
getTextElement(color: any): any {
let nThreshold = 105;
let bgDelta = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
let foreColor = 255 - bgDelta < nThreshold ? 'Black' : 'White';
return foreColor;
}
tickLabelFormatFunction: any = (value: any) => {
if (value == 0) return value;
if (value == 255) return value;
return '';
};
tooltipFormatFunction: any = (value: any) => {
if (this.redSlider().mode() === 'default') {
if (value < 10) return new Number(value.toPrecision(3));
if (value > 10 && value < 100) return new Number(value.toPrecision(4));
else return new Number(value.toPrecision(5));
} else {
if (value < 10) return new Number(value.toPrecision(3));
if (value > 10 && value < 256) return new Number(value.toPrecision(4));
}
return undefined;
};
}html, body {
width: 100vw;
height: 100vh;
padding: 0;
margin: 0;
}
.colorBlock {
border: 1px solid #aaa;
width: 200px;
height: 200px;
float: right;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.colorLabel {
padding: 6px;
}
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 event is triggered when the value of the slider is changed.
<jqxSlider (onChange)="onChange($event)"></jqxSlider>
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.
<jqxSlider #mySlider></jqxSlider>
import { Component, viewChild } from '@angular/core';
import { jqxSliderModule, jqxSliderComponent } from 'jqwidgets-ng/jqxslider';
@Component({
selector: 'app-root',
imports: [jqxSliderModule],
templateUrl: './app.html'
})
export class App {
readonly mySlider = viewChild.required<jqxSliderComponent>('mySlider');
run(): void {
const value = this.mySlider().val();
console.log(value);
}
}