The Angular ListBox comes with several useful events. When the user selects an item, the 'select' and 'unselect' events are triggered.
Loading...

Angular ListBox: Events

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.

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

app.html

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

Learn more

More Angular ListBox demos