Open In App

Angular PrimeNG Form MultiSelect Properties 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 Angular PrimeNG Form MultiSelect Properties Component.

The Multiselect component is used to provide the user with a list of options where one or more than one options can be selected by the user. The properties of the MultiSelect Component are listed below.



Syntax:

<p-multiSelect 
    [options]="..." 
    [(ngModel)]="..."
    ... 
    defaultLabel="..." 
    optionLabel="..."
    [disabled]="..."
    display="...">
</p-multiSelect>

Angular PrimeNG Form MultiSelect Properties:



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: The project structure will look like the following:

Project Structure

Example1: In the below code, we will be using the above properties to demonstrate the use of the Angular PrimeNG Form MultiSelect Properties Component.




<div style="text-align:center">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</h3>
    <h4>
        Angular PrimeNG Form MultiSelect
        Properties Component
    </h4>
    <h5>Chips</h5>
 
    <p-multiSelect
        [options]="cities"
        [(ngModel)]="selectedCities"
        defaultLabel="Select a City"
        optionLabel="name"
        display="chip">
    </p-multiSelect>
</div>




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
 
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
})
 
export class AppComponent {
    cities: any[];
    selectedCities: string[] = [];
 
    constructor(private primengConfig: PrimeNGConfig) {
        this.cities = [
            { name: "Nallasopara", code: "Nallasopara" },
            { name: "Naigaon", code: "Naigaon" },
            { name: "Mira road", code: "MR" },
            { name: "Vasai", code: "VASAI" },
            { name: "Virar", code: "virar" }
        ];
    }
 
    ngOnInit() {
        this.primengConfig.ripple = true;
    }
}




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 { MultiSelectModule }
    from 'primeng/multiselect';
 
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MultiSelectModule,
        FormsModule,
        HttpClientModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
 
export class AppModule { }

Output:

 

Example 2: In this example, we used the disabled property of the Multiselect component to disable the component.




<div style="text-align:center">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</h3>
    <h4>
        Angular PrimeNG Form
        MultiSelect Properties Component
    </h4>
 
    <h5>Basic</h5>
    <p-multiSelect
        [options]="cities"
        [(ngModel)]="selectedCities1"
        defaultLabel="Select a City"
        optionLabel="name"
        [disabled]="true">
    </p-multiSelect>
</div>




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
 
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
})
export class AppComponent {
    cities: any[];
    selectedCities1: any[] = [];
 
    constructor(private primengConfig: PrimeNGConfig)
    {
        this.cities = [
            { name: "Nallasopara", code: "Nallasopara" },
            { name: "Naigaon", code: "Naigaon" },
            { name: "Mira road", code: "MR" },
            { name: "Vasai", code: "VASAI" },
            { name: "Virar", code: "virar" }
        ];
    }
 
    ngOnInit() {
        this.primengConfig.ripple = true;
    }
}




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 { MultiSelectModule }
    from 'primeng/multiselect';
 
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MultiSelectModule,
        FormsModule,
        HttpClientModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
 
export class AppModule { }

Output:

 

Reference: https://www.primefaces.org/primeng/multiselect


Article Tags :