Open In App

Angular PrimeNG Form SelectButton Selection 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 Form SelectButton Selection Component in Angular PrimeNG.

The SelectButton Component is used to make a group of buttons from which the user can select a value. In the  Selection Component, the SelectButton permits the selection of either single or multiple items, which depends on the behavior defined with the multiple property.



Angular PrimeNG Form SelectButton Selection Component 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: It will look like the following:

 

ng serve --save

Example 1: This is the basic example that shows how to use the Angular PrimeNG Form SelectButton Selection Component using multiple=”true”.




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form SelectButton
    Selection Component.
</h5>
 
<p-selectButton optionLabel="name"
                [options]="gfg"
                [multiple]="true">
</p-selectButton>




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
 
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
 
export class AppComponent {
    gfg: any[];
    constructor(private primeNGConfig: PrimeNGConfig) {
        this.gfg = [
            { name: 'Geek 1' },
            { name: 'Geek 2' },
            { name: 'Geek 3' },
        ];
    }
}




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

Output:

 

Example 2: This is the basic example that shows how to use the Angular PrimeNG Form SelectButton Selection Component using multiple=”false”.




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Form SelectButton
    Selection Component.
</h5>
 
<p-selectButton optionLabel="name"
                [options]="gfg"
                [multiple]="false">
</p-selectButton>




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
 
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
 
export class AppComponent {
    gfg: any[];
    constructor(private primeNGConfig: PrimeNGConfig) {
        this.gfg = [
            { name: 'Geek 1' },
            { name: 'Geek 2' },
            { name: 'Geek 3' },
        ];
    }
}




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

Output:

 

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


Article Tags :