The Angular ListBox can display checkboxes next to its items. You can enable this feature by setting the 'checkboxes' property to true.
Loading...

Angular ListBox: CheckBoxes

Display checkboxes next to the items 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, ElementRef, AfterViewInit, 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 Events = viewChild.required<ElementRef>('Events');
    readonly CheckedItems = viewChild.required<ElementRef>('CheckedItems');

    ngAfterViewInit(): void {
        this.myListBox().checkIndex(0);
        this.myListBox().checkIndex(1);
        this.myListBox().checkIndex(2);
        this.myListBox().checkIndex(5);
    }

    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"
    ];

    checkChange(event: any): void {
        let eventsContainer = this.Events().nativeElement;
        let checkedItemsContainer = this.CheckedItems().nativeElement;

        if (event.args.checked) {
            eventsContainer.innerHTML = 'Checked: ' + event.args.label;
        }
        else {
            eventsContainer.innerHTML = 'Unchecked: ' + event.args.label;
        }

        let items = this.myListBox().getCheckedItems();
        let checkedItems = '';
        for (let i = 0; i < items.length; i++) {
            if (i < items.length - 1) {
                checkedItems += items[i].label + ', ';
            }
            else checkedItems += items[i].label;
        }

        checkedItemsContainer.innerHTML = checkedItems;
    };
}

app.html

<jqxListBox #jqxListBox
            (onCheckChange)="checkChange($event)"
            [source]="source"
            [checkboxes]="true"
            [width]="200"
            [height]="250">
</jqxListBox>

<div style="font-size: 13px; font-family: Verdana; margin-top: 20px;" #Events></div>
<div style="font-size: 13px; font-family: Verdana; margin-top: 10px;" #CheckedItems></div>

Learn more

More Angular ListBox demos