Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • AngularJS Tutorial
  • AngularJS Directives
  • AngularJS Functions
  • AngularJS Filters
  • AngularJS Examples
  • AngularJS Interview Questions
  • Angular ngx Bootstrap
  • AngularJS Cheat Sheet
  • AngularJS PrimeNG
  • JavaScript
  • Web Technology
Open In App
Next Article:
Angular PrimeNG Form MultiSelect Component
Next article icon

Angular PrimeNG ListBox Component

Last Updated : 22 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the ListBox component in Angular PrimeNG.

ListBox component: It is used to make a list component from which we can select one or more items and can also be discarded if the item is not required by unchecking in the list.

Properties:

  • ariaFilterLabel: It is used to define a string that labels the input filter element. It is of string data type, the default value is null.
  • checkbox: It is used to allow selecting items with checkboxes. It is of boolean data type, the default value is false.
  • dataKey: It is the property that is used to Identify an option. It is of string data type, the default value is null.
  • disabled: It specifies that the element should be disabled. It is of the boolean data type, the default value is false.
  • filter: It is used to display a filter input at the header. It is of boolean data type, the default value is false.
  • filterMatchMode: It is used to define how the items are filtered. It is of string data type, the default value is contained.
  • filterValue: It is used to specify filter displays with this value. It is of string data type, the default value is null.
  • filterLocale: It is used to set the locale to use in filtering. It is of string data type, the default value is undefined.
  • filterPlaceHolder: It is used to define the placeholder of the filter input. It is of string data type, the default value is null.
  • listStyle: It is used to set the Inline style of the list element, It is of string data type, the default value is null.
  • listStyleClass: It is used to set the Style class of the list element, It is of string data type, the default value is null.
  • metaKeySelection: It is used to defines how multiple items can be selected. It is of the boolean data type, the default value is true.
  • multiple: It is used to allow selecting multiple values. It is of the boolean data type, the default value is false.
  • readonly: it specifies that the element value cannot be changed. It is of the boolean data type, the default value is false.
  • emptyMessage: It is used to set the text to display when there is no data. It is of string data type, the default value is no records found.
  • emptyFilterMessage: It is used to set the text to display when filtering does not return any results, It is of string data type, the default value is no records found.
  • options: It is an array representing select items to display as the available options, It is of array data type, the default value is null.
  • optionLabel: It is used to give the label of an option, It is of string data type, the default value is the label.
  • optionValue: It is used to give the value of an option, defaults to the option itself when not defined. It is of string data type, the default value is value.
  • optionGroupLabel: It is used to give a label to the option group. It is of string data type, the default value is the label.
  • optionGroupChildren: It is used to get the name of the options field of the option group. It is of string data type, the default value is an item.
  • group: It is used to set whether to display options as grouped when nested options are provided. It is of the boolean data type, the default value is false.
  • showToggleAll: It is used to set whether the header checkbox is shown in multiple modes. It is of the boolean data type, the default value is true.
  • style: It is used to set the inline style of the element. It is of string data type, the default value is null.
  • styleClass: It is used to set the style class of the element. It is of string data type, the default value is null.

Events:

  • onChange: It is a callback that is fired when the value of the list box changes.
  • onDblClick: It is a callback that is fired when an item is double-clicked.
  • onClick: It is a callback that is fired when the Listbox option clicks.
 

Styling:

  • p-listbox: It is used for the container of an element.
  • p-listbox-list: It is used as a container for the list.
  • p-listbox-item: It is used to keep the item in the list.
  • p-listbox-header: It is used to show the header of the element.
  • p-listbox-filter-container: It is a container of filter input in the header.

Creating Angular application & module installation:

  • Step 1: Create an Angular application using the following command.

    ng new appname
  • Step 2: After creating your project folder i.e. appname, move to it using the following command.

    cd appname
  • Step 3: Install PrimeNG in your given directory.

    npm install primeng --save  npm install primeicons --save

Project Structure: After completing the above processes, it will look like the following.

 

Example 1: This is the basic example that shows how to use the ListBox component. 

app.component.html
<h2>GeeksforGeeks</h2> <h5>PrimeNG ListBox component</h5> <p-listbox   [options]="gfg"   [(ngModel)]="selectedCourse"   optionLabel="name"   [style]="{'width':'15rem'}"> </p-listbox> 
app.module.ts
import { NgModule } from "@angular/core"; import { BrowserModule }      from "@angular/platform-browser"; import { FormsModule } from "@angular/forms"; import { BrowserAnimationsModule }      from "@angular/platform-browser/animations"; import { AppComponent } from "./app.component"; import { ListboxModule } from "primeng/listbox";  @NgModule({   imports: [BrowserModule,                BrowserAnimationsModule,              ListboxModule, FormsModule],   declarations: [AppComponent],   bootstrap: [AppComponent], }) export class AppModule {} 
app.component.ts
import { Component } from "@angular/core"; import { PrimeNGConfig, SelectItemGroup } from "primeng/api";  interface Course {   name: string; }  @Component({   selector: "my-app",   templateUrl: "./app.component.html",   styles: [], }) export class AppComponent {   gfg: Course[];   selectedCourse: Course;    constructor(private primengConfig: PrimeNGConfig) {     this.gfg = [       { name: "HTML5" },       { name: "JavaScript" },       { name: "Java" },       { name: "ReactJS" },       { name: "AngularJS" },     ];   } } 

Output:

Example 2: In this example, we will make a dynamic listBox Group. 

app.component.html
<h2>GeeksforGeeks</h2> <h5>PrimeNG ListBox Component</h5> <p-listbox [options]="gfg" [checkbox]="true"             [filter]="true" [multiple]="true"             optionLabel="name"> </p-listbox> 
app.module.ts
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule }      from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; import { ListboxModule } from 'primeng/listbox'; import { ButtonModule } from 'primeng/button';  @NgModule({   imports: [BrowserModule,                BrowserAnimationsModule,              ListboxModule, FormsModule],   declarations: [AppComponent],   bootstrap: [AppComponent] }) export class AppModule {} 
app.component.ts
import { Component } from '@angular/core'; import { PrimeNGConfig } from 'primeng/api'; interface Course {   name: string; }  @Component({   selector: 'my-app',   templateUrl: './app.component.html' }) export class AppComponent {   gfg: any[];    constructor(private primengConfig: PrimeNGConfig) {     this.gfg = [       { name: 'AngularJS' },       { name: 'ReactJS' },       { name: 'Java' },       { name: 'JavaScript' },       { name: 'HTML' },       { name: 'PrimeNG' },       { name: 'Bootstrap' }     ];   }    ngOnInit() {     this.primengConfig.ripple = true;   } } 

Output:

Reference: https://primefaces.org/primeng/showcase/#/listbox


Next Article
Angular PrimeNG Form MultiSelect Component
author
taran910
Improve
Article Tags :
  • Web Technologies
  • AngularJS
  • Angular-PrimeNG

Similar Reads

  • Angular PrimeNG Form AutoComplete Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that helps to create an attractive user interface with enhanced functionality. These components can be utilized for great styling & are used to make responsive websites with very much ease. There are diff
    12 min read
  • Angular PrimeNG Calendar Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the calendar component in angular ngx bootstrap. Calendar c
    8 min read
  • Angular PrimeNG Form CascadeSelect Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Angular PrimeNG Form CascadeSelect Component. The CascadeSe
    6 min read
  • Angular PrimeNG Form Checkbox Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the calendar component in angular ngx bootstrap. Checkbox Compo
    5 min read
  • Angular PrimeNG Chips Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Chips component in Angular PrimeNG. Chips component: It
    5 min read
  • Angular PrimeNG ColorPicker Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the colorPicker component in Angular PrimeNG. colorPicker c
    5 min read
  • Angular PrimeNG Dropdown Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Dropdown component in Angular ngx Bootstrap. We will al
    9 min read
  • Angular PrimeNG Form Editor Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will see how to use the Form Editor Component in Angular PrimeNG. The Form Edito
    3 min read
  • Angular PrimeNG FloatLabel Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the FloatLabel component in angular PrimeNG. FloatLabel com
    2 min read
  • Angular PrimeNG InputGroup Component
    Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the InputGroup component in angular primeNG. InputGroup com
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences