The events that occur in Angular ListBox.
A live Angular example of jqxListBox, the jQWidgets ListBox component, with its complete source code below. It is one of 18 jqxListBox demos for Angular.
height property – Sets or gets the listbox's height.source property – Sets or gets the item's source.width property – Sets or gets the listbox's width.select event – This event is triggered when the user selects an item.unselect event – This event is triggered when the user unselects an item.getItem method – Gets an item by index.To run it in your own app, install the package with npm install jqwidgets-ng, add these files to a standalone Angular CLI app, and add jqx.base.css and a theme to the styles in angular.json. Getting started with jqxListBox shows the setup step by step.
import { Component, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxListBoxComponent } from 'jqwidgets-ng/jqxlistbox';
import { jqxPanelComponent } from 'jqwidgets-ng/jqxpanel';
import { CommonModule } from '@angular/common';
import { jqxListBoxModule } from 'jqwidgets-ng/jqxlistbox';
import { jqxPanelModule } from 'jqwidgets-ng/jqxpanel';
@Component({
imports: [CommonModule, jqxListBoxModule, jqxPanelModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App {
readonly myListBox = viewChild.required<jqxListBoxComponent>('jqxListBox');
readonly myPanel = viewChild.required<jqxPanelComponent>('Events');
source: string[] = [
"Affogato",
"Americano",
"Bicerin",
"Breve",
"Café Bombón",
"Café au lait",
"Caffé Corretto",
"Café Crema",
"Caffé Latte",
"Caffé macchiato",
"Café mélange",
"Coffee milk",
"Cafe mocha",
"Cappuccino",
"Carajillo",
"Cortado",
"Cuban espresso",
"Espresso",
"Eiskaffee",
"The Flat White",
"Frappuccino",
"Galao",
"Greek frappé coffee",
"Iced Coffee",
"Indian filter coffee",
"Instant coffee",
"Irish coffee",
"Liqueur coffee"
];
select(event: any): void {
let item = this.myListBox().getItem(event.args.index);
if (item != null) {
this.myPanel().prepend('<div style="margin-top: 5px;">Selected: ' + item.label + '</div>');
}
}
unselect(event: any): void {
let item = this.myListBox().getItem(event.args.index);
if (item != null) {
this.myPanel().prepend('<div style="margin-top: 5px;">Unselected: ' + item.label + '</div>');
}
}
}
<div style='float: left; width: 500px;' #jqxWidget>
<jqxListBox style="margin-left: 20px; margin-top: 10px; float: left;" #jqxListBox
(onSelect)="select($event)"
(onUnselect)="unselect($event)"
[source]="source"
[width]="200"
[height]="250">
</jqxListBox>
<div style='margin-left: 20px; margin-top: 10px; float: left;'>
<div>
<span>
Events:
</span>
<jqxPanel #Events [width]="200" [height]="250">
</jqxPanel>
</div>
</div>
</div>