Angular PrimeNG Panel Component - GeeksforGeeks

07 Oct, 2021
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 Panel component in Angular PrimeNG. We will also learn about the properties, events & styling along with their syntaxes that will be used in the code. 
Panel Component: It allows us to make an element containing a header and some content associated with that header. 
Properties:
header: It is the header text of the panel. It is of string data type, the default value is null.
toggleable: It defines that the content of the panel can be expanded and collapsed or not. It is of boolean data type, the default value is false.
collapsed: It defines the initial state of the panel content. It is of boolean data type, the default value is false.
style: It is an inline style of the component. It is of string data type, the default value is null.
styleClass: It is the style class of the component. It is of string data type, the default value is null.
expandIcon: It is the expand icon of the toggle button. It is of string data type, the default value is pi pi-plus.
collapseIcon: It is the collapsed icon of the toggle button. It is of string data type, the default value is pi pi-minus.
showHeader: It specifies if the header of a panel cannot be displayed. It is of boolean data type, the default value is true.
transitionOptions: It is the transition option of the animation. It is of string data type, the default value is 400ms cubic-bezier(0.86, 0, 0.07, 1).
toggler: It specifies if the toggler element to toggle the panel content. It is of string data type, the default value is an icon.
Event:
onBeforeToggle: It is a callback that is fired before content toggle.
onAfterToggle: It is a callback that is fired after content toggle.
 
Styling:
p-panel: It is the container element.
p-panel-titlebar: It is the header section.
p-panel-title: It is the title text of the panel.
p-panel-titlebar-toggler: It is the toggle icon.
p-panel-content: It is the content of the 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:
Example 1: This is the basic example that illustrates how to use the Panel component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG Panel Component</h5><p-panel header="Angular PrimeNG">   <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>
app.component.ts
import { Component } from '@angular/core';  @Component({  selector: 'my-app',  templateUrl: './app.component.html',  styleUrls: ['./app.component.scss']})export class AppComponent {}
 
app.module.ts
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";  @NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             PanelModule],  declarations: [AppComponent],  bootstrap: [AppComponent],})export class AppModule {}
Output:
Example 2: In this example, we will know how to use the toggleable property in the Panel component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG Panel Component</h5><p-panel header="Angular PrimeNG" toggleable="true">   <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>
app.component.ts
import { Component } from '@angular/core';  @Component({  selector: 'my-app',  templateUrl: './app.component.html',  styleUrls: ['./app.component.scss']})export class AppComponent {}
app.module.ts
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";  @NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             PanelModule],  declarations: [AppComponent],  bootstrap: [AppComponent],})export class AppModule {}
Output:
Reference: https://primefaces.org/primeng/showcase/#/panel
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular PrimeNG Messages Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?