In this demo the Angular ListBox is bound to XML data.
Loading...

Angular ListBox: Binding to XML

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.

jqxListBox API used in this demo

Source code

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.

app.ts

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);
            }
        }
    };
}

app.html

<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>

Learn more

More Angular ListBox demos