Angular ListBox's binding to XML.
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.
displayMember property – Sets or gets the displayMember of the Items.height property – Sets or gets the listbox's height.source property – Sets or gets the item's source.valueMember property – Sets or gets the valueMember of the Items.width property – Sets or gets the listbox's width.select event – This event is triggered when the user selects an 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, 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 {
readonly selectionlog = viewChild.required<ElementRef>('selectionlog');
url: string = "./../../../sampledata/customers.xml";
// prepare the data
source: any = {
datatype: "xml",
datafields: [
{ name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName' },
{ name: 'ContactName', map: 'm\\:properties>d\\:ContactName' },
],
root: "entry",
record: "content",
id: 'm\\:properties>d\\:CustomerID',
url: this.url
};
dataAdapter: any = new jqx.dataAdapter(this.source, { async: false });
select(event: any): void {
if (event.args) {
let item = event.args.item;
if (item) {
let valueElement = document.createElement('div');
let labelElement = document.createElement('div');
valueElement.innerHTML = 'Value: ' + item.value;
labelElement.innerHTML = 'Label: ' + item.label;
let selectionLog = this.selectionlog().nativeElement;
selectionLog.innerHTML = '';
selectionLog.appendChild(labelElement);
selectionLog.appendChild(valueElement);
}
}
};
}
<jqxListBox #jqxListBox
(onSelect)="select($event)"
[source]="dataAdapter"
[displayMember]="'ContactName'"
[valueMember]="'CompanyName'"
[height]="200"
[width]="250">
</jqxListBox>
<div style="font-size: 13px; font-family: Verdana;" #selectionlog>
</div>