Open In App

Angular PrimeNG Form Listbox Disabled Options Component

Improve
Improve
Like Article
Like
Save
Share
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 see how to use the Form Listbox Disabled Options Component in Angular PrimeNG.

The ListBox component 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. By enabling the optionDisabled property, which prevents the particular options from getting selected.

Syntax:

<p-listbox [options]="..." 
           [(ngModel)]="..." 
           optionDisabled="inactive">
</p-listbox>

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:

 

  • Steps to run the application: Run the below command to see the output:
ng serve --open

Example 1: Below is the example that illustrates the use of the Angular PrimeNG Form Listbox Disabled Options Component.

  • app.component.html:

HTML




<h1 style="color: green">
  GeeksforGeeks
</h1>
<h5>
  Angular PrimeNG Form Listbox 
  Disabled Options Component
</h5>
  
<p-listbox [options]="gfg" 
           optionLabel="name" 
           optionDisabled="activeStatus">
</p-listbox>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
  
interface City {
    name: string;
    activeStatus: boolean;
}
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent {
    gfg: City[];
    constructor() {
        this.gfg = [
            { name: 'AngularJS', activeStatus: false },
            { name: 'ReactJS', activeStatus: true },
            { name: 'JavaScript', activeStatus: false },
            { name: 'PrimeNG', activeStatus: true },
            { name: 'Bootstrap', activeStatus: false }
        ];
    }
}


  • app.module.ts:

Javascript




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


Output:

 

Example 2: Below is another example that illustrates the use of the Angular PrimeNG Form Listbox Disabled Options Component using a filter, multiple, and the checkbox value to be true. 

  • app.component.html:

HTML




<h1 style="color: green">
  GeeksforGeeks
</h1>
<h5>
      Angular PrimeNG Form Listbox 
      Disabled Options Component
</h5>
  
<p-listbox [options]="gfg" 
           optionLabel="name" 
           optionDisabled="activeStatus"
           [filter]="true" 
           [multiple]="true" 
           [checkbox]="true">
</p-listbox>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
  
interface City {
    name: string;
    activeStatus: boolean;
}
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent {
    gfg: City[];
    constructor() {
        this.gfg = [
            { name: 'AngularJS', activeStatus: false },
            { name: 'ReactJS', activeStatus: true },
            { name: 'JavaScript', activeStatus: false },
            { name: 'PrimeNG', activeStatus: true },
            { name: 'Bootstrap', activeStatus: false }
        ];
    }
}


  • app.module.ts:

Javascript




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


Output:

 

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



Last Updated : 01 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads