Angular UI Components Documentation
The Angular ColorPicker enables the user to easily pick a color. This guide adds the Angular ColorPicker (jqxColorPicker) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxcolorpicker 
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 jqxColorPickerModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxColorPickerModule } from 'jqwidgets-ng/jqxcolorpicker';
@Component({
selector: 'app-root',
imports: [jqxColorPickerModule],
templateUrl: './app.html'
})
export class App {}
The source of the live Default Functionality demo.
<jqxScrollView [width]='500' [height]='350' [slideShow]='true' [showButtons]='false'>
<div>
<div class="photo" style="background-image: url(https://www.jqwidgets.com/angular/images/imageNature1.jpg)"></div>
</div>
<div>
<div class="photo" style="background-image: url(https://www.jqwidgets.com/angular/images/imageNature2.jpg)"></div>
</div>
<div>
<div class="photo" style="background-image: url(https://www.jqwidgets.com/angular/images/imageNature3.jpg)"></div>
</div>
<div>
<div class="photo" style="background-image: url(https://www.jqwidgets.com/angular/images/imageNature4.jpg)"></div>
</div>
<div>
<div class="photo" style="background-image: url(https://www.jqwidgets.com/angular/images/imageNature5.jpg)"></div>
</div>
</jqxScrollView>
<br />
<label style="margin-left: 5px; font-size: 12px; font-family: Verdana;">
Select Frame color
</label>
<br />
<jqxDropDownButton #dropDownButton style="margin: 3px; float: left"
[width]='150' [height]='22'>
<div style="padding: 3px;">
<jqxColorPicker (onColorchange)="colorPickerEvent($event)"
[width]='220' [height]='220' [colorMode]='"hue"'>
</jqxColorPicker>
</div>
</jqxDropDownButton>
import { Component, AfterViewInit, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxDropDownButtonComponent } from 'jqwidgets-ng/jqxdropdownbutton';
import { CommonModule } from '@angular/common';
import { jqxColorPickerModule } from 'jqwidgets-ng/jqxcolorpicker';
import { jqxDropDownButtonModule } from 'jqwidgets-ng/jqxdropdownbutton';
import { jqxScrollViewModule } from 'jqwidgets-ng/jqxscrollview';
@Component({
imports: [CommonModule, jqxColorPickerModule, jqxDropDownButtonModule, jqxScrollViewModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App implements AfterViewInit {
readonly myDropDown = viewChild.required<jqxDropDownButtonComponent>('dropDownButton');
ngAfterViewInit(): void {
this.myDropDown().setContent(
this.getTextElementByColor({ hex: 'FFAABB', r: 255, g: 170, b: 187 })
);
}
getTextElementByColor(color: any): any {
if (color == 'transparent' || color.hex == '') {
return '<div style="text-shadow: none; position: relative; padding-bottom: 2px; margin-top: 2px;">transparent</div>';
}
let nThreshold = 105;
let bgDelta = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
let foreColor = 255 - bgDelta < nThreshold ? 'Black' : 'White';
let element =
'<div style="text-shadow: none; position: relative; padding-bottom: 2px; margin-top: 2px;color:' +
foreColor +
'; background: #' +
color.hex +
'">#' +
color.hex +
'</div>';
return element;
}
colorPickerEvent(event: any): void {
this.myDropDown().setContent(this.getTextElementByColor(event.args.color));
(<HTMLElement>document.getElementsByClassName('jqx-scrollview')[0]).style.borderColor =
'#' + event.args.color.hex;
}
}
.photo {
width: 500px;
height: 350px;
background-color: #000;
background-position: center;
background-repeat: no-repeat;
}
.jqx-scrollview {
border: 15px solid #ffaabb;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
Options are inputs, bound with [name]="value".
Events are outputs named on plus the event name with a capital first letter. For example, colorchange: This event is triggered when a new color is picked.
<jqxColorPicker (onColorchange)="onColorchange($event)"></jqxColorPicker>
onColorchange(event: any): void {
console.log(event.args);
}
Get the component with a signal query and call its methods. For example, getColor: Gets the color.
<jqxColorPicker #myColorPicker></jqxColorPicker>
import { Component, viewChild } from '@angular/core';
import { jqxColorPickerModule, jqxColorPickerComponent } from 'jqwidgets-ng/jqxcolorpicker';
@Component({
selector: 'app-root',
imports: [jqxColorPickerModule],
templateUrl: './app.html'
})
export class App {
readonly myColorPicker = viewChild.required<jqxColorPickerComponent>('myColorPicker');
run(): void {
const result = this.myColorPicker().getColor();
console.log(result);
}
}