Angular PrimeNG Form SelectButton Custom Content 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 Angular PrimeNG Form SelectButton Custom Content Component.
Form SelectButton Custom Content: Create an ng-template for supporting custom content when the local ng-template variable points to a choice from the options collection.
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:

Steps to run the application: Run the below command to see the output
ng serve --save
Example 1: Below is the example code that illustrates the use of the Angular PrimeNG Form SelectButton Custom Content Component.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h4 > Angular PrimeNG Form SelectButton Custom Content Component. </ h4 > < p-selectButton [options]="gfg"> < ng-template let-item> < i [class]="item.icon" ></ i > </ ng-template > </ p-selectButton > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent { gfg: any[]; constructor() { this .gfg = [ { icon: 'pi pi-whatsapp' }, { icon: 'pi pi-instagram' }, { icon: 'pi pi-twitter' }, { icon: 'pi pi-telegram' }, ]; } } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import {SelectButtonModule} from 'primeng/selectbutton' ; import {ButtonModule} from 'primeng/button' ; @NgModule({ imports: [ BrowserAnimationsModule, SelectButtonModule, ButtonModule, ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Example 2: Below is another example code that illustrates the use of the Angular PrimeNG Form SelectButton Custom Content Component.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h4 > Angular PrimeNG Form SelectButton Custom Content Component. </ h4 > < p-selectButton [options]="gfg"> < ng-template let-item> < button pButton pRipple type = "button" label={{item.icon}} class = "p-button-{{item.color}}" > </ button > </ ng-template > </ p-selectButton > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent { gfg: any[]; constructor() { this .gfg = [ { icon: "I'm Success" , color: "success" }, { icon: "I'm Danger" , color: "danger" }, { icon: "I'm Warning" , color: "warning" }, { icon: "I'm Info" , color: "info" }, ]; } } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import {SelectButtonModule} from 'primeng/selectbutton' ; import {ButtonModule} from 'primeng/button' ; @NgModule({ imports: [ BrowserAnimationsModule, SelectButtonModule, ButtonModule, ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Reference: https://primefaces.org/primeng/selectbutton
Please Login to comment...