Angular ListBox's data that was selected from another existing element.
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.width property – Sets or gets the listbox's width.select event – This event is triggered when the user selects an item.ensureVisible method – Ensures that an item is visible.loadFromSelect methodselectIndex method – Selects item.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, AfterViewInit, ElementRef, viewChild } from '@angular/core';
import { jqxListBoxComponent } from 'jqwidgets-ng/jqxlistbox';
import { CommonModule } from '@angular/common';
import { jqxListBoxModule } from 'jqwidgets-ng/jqxlistbox';
@Component({
imports: [CommonModule, jqxListBoxModule],
selector: 'app-root',
templateUrl: './app.html'
})
export class App implements AfterViewInit {
readonly myListBox = viewChild.required<jqxListBoxComponent>('jqxListBox');
readonly select = viewChild.required<ElementRef>('select');
ngAfterViewInit() {
this.myListBox().loadFromSelect('select');
}
updating = false;
change(event: any): void {
this.updating = true;
let index = this.select().nativeElement.selectedIndex;
this.myListBox().selectIndex(index);
this.myListBox().ensureVisible(index);
this.updating = false;
};
selectItem(event: any): void {
if (event.args && !this.updating) {
// select the item in the 'select' tag.
let index = event.args.item.index;
this.select().nativeElement.selectedIndex = index;
}
};
}
<div style="float: left;">
<jqxListBox #jqxListBox
(onSelect)="selectItem($event)"
[width]="200"
[height]="250">
</jqxListBox>
</div>
<div style='float: left;' #Select>
<select style='height: 250px; width: 200px; margin-left: 30px;' size='2' id='select' #select (change)="change($event)">
<option>Affogato</option>
<option>Americano</option>
<option>Bicerin</option>
<option>Breve</option>
<option>Café Bombón</option>
<option>Caffé Corretto</option>
<option>Café Crema</option>
<option>Caffé Latte</option>
<option>Caffé macchiato</option>
<option>Café mélange</option>
<option>Coffee milk</option>
<option>Cafe mocha</option>
<option>Cappuccino</option>
<option>Carajillo</option>
<option>Cuban espresso</option>
<option>Espresso</option>
<option selected="true">The Flat White</option>
<option>Frappuccino</option>
<option>Galao</option>
<option>Greek frappé coffee</option>
<option>Iced Coffee</option>
<option>Indian filter coffee</option>
<option>Instant coffee</option>
<option>Irish coffee</option>
<option>Liqueur coffee</option>
</select>
</div>