Angular PrimeNG Panel Custom Icons
Last Updated :
01 Dec, 2022
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 Panel Custom Icons Component in Angular PrimeNG.
The Panel Component allows us to make an element containing a header and some content associated with that header. The Custom Icons provide the other icons to be included in the header section of the panel by specifying the icons selector. Including the .p-panel-header-icon class in the icon can provide a unique icon view.
Syntax:
<p-panel>
<ng-template pTemplate="icons">
<button pButton (click)="..."
class="p-panel-header-icon p-link">
<span class="..."></span>
</button>
<p-menu #menu id="..." [model]="..."
[popup]="true">
</p-menu>
</ng-template>
</p-panel>
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:
- To run the above file run the below command:
ng serve --save
Example 1: This basic example illustrates how to use the Angular PrimeNG Panel Custom Icons.
HTML
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG Panel Custom Icon Component</ h5 >
< p-panel >
< ng-template pTemplate = "icons" >
< button pButton class = "p-panel-header-icon"
(click)="menu.toggle($event)">
< span class = "pi pi-code" ></ span >
</ button >
< p-menu #menu [model]="gfg"
[popup]="true">
</ p-menu >
</ ng-template >
< p >
Angular PrimeNG is a framework used
with angular to create components with
great styling and this framework is
very easy to use and is used to make
responsive websites.
</ p >
</ p-panel >
|
Javascript
import { Component } from '@angular/core' ;
import {MessageService} from 'primeng/api' ;
import {MenuItem} from 'primeng/api' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
providers: [MessageService]
})
export class AppComponent {
gfg: MenuItem[];
ngOnInit() {
this .gfg = [
{
label: 'Courses' ,
items: [{
label: 'DSA Self-Paced'
},
{
label: 'C++ STL Self-Paced' ,
},
{
label: 'System Design' ,
}
]}
];
}
}
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { RouterModule } from '@angular/router' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { PanelModule } from 'primeng/panel' ;
import { MenuModule } from 'primeng/menu' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
PanelModule,
MenuModule,
RouterModule.forRoot([
{ path: '' , component: AppComponent }
])
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
|
Output:
Example 2: This is another basic example illustrating how to use the Angular PrimeNG Panel Custom Icons using the icons in the footer.
HTML
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h5 >
Angular PrimeNG Panel Custom Icon Component
</ h5 >
< p-panel [toggleable]="true">
< p >
GeeksforGeeks, It is a Computer
Science Portal for all Geeks.
</ p >
< ng-template pTemplate = "footer" >
< button pButton>
< i class = "pi pi-facebook" ></ i >
</ button >
< button pButton>
< i class = "pi pi-instagram" ></ i >
</ button >
< button pButton>
< i class = "pi pi-twitter" ></ i >
</ button >
< button pButton>
< i class = "pi pi-linkedin" ></ i >
</ button >
</ ng-template >
</ p-panel >
|
Javascript
import { Component } from '@angular/core' ;
import {MessageService} from 'primeng/api' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
providers: [MessageService]
})
export class AppComponent { }
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule }
from '@angular/platform-browser' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { PanelModule } from 'primeng/panel' ;
import { ButtonModule } from 'primeng/button' ;
import { MenuModule } from 'primeng/menu' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
PanelModule,
ButtonModule,
MenuModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
|
Output:
Reference: https://primefaces.org/primeng/panel
Share your thoughts in the comments
Please Login to comment...