Angular PrimeNG Accordion Tab Change Event
Last Updated :
28 Apr, 2025
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 learn about the Angular PrimeNG Accordion Tab Change Event.
The Accordion Component is used to display a section of custom content in tabs. The selected property that is set true, which allows either one-way binding or two-way binding, specifies the content’s visibility.
Angular PrimeNG Accordion Tab Change Event:
- onClose: It is invoked when an active tab is collapsed by clicking on the header.
- onOpen: It is invoked when a tab gets expanded.
Syntax:
<p-accordion
(event)=function()>
...
</p-accordion>
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:
Steps to run the application: Run the below command to see the output
ng serve --save
Example 1: Below is the basic example code that illustrates the use of Angular PrimenNG Accordion Tab Change. In this example, we will learn about the onClose event
HTML
<div style="width: 50%;">
<h2 style="color: green;">GeeksforGeeks</h2>
<h3>Angular PrimeNG Accordion Tab Change Event</h3>
<p-accordion [multiple]="true" (onClose)="onClose()">
<p-accordionTab header="Complete Interview Preparation">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/complete-interview-preparation-thumbnail.png?v=19265"
height="300" width="350" alt="gfg"/>
</p-accordionTab>
<p-accordionTab header="System Design">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/system-design-live-thumbnail.png?v=19265"
height="300" width="350" alt="gfg" />
</p-accordionTab>
<p-accordionTab header="C++ STL Self-Paced">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/cpp-stl-thumbnail.png?v=19265"
height="300" width="350" alt="gfg"/>
</p-accordionTab>
</p-accordion>
</div>
JavaScript
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
onClose(){
alert("Accordion is Closed")
}
}
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 { AccordionModule } from 'primeng/accordion';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
AccordionModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
Output:
Example 2: Below is another example code that illustrates the use of Angular PrimenNG Accordion Tab Change. In this example, we will learn about the onOpen event.
HTML
<div style="width: 50%;">
<h2 style="color: green;">GeeksforGeeks</h2>
<h3>Angular PrimeNG Accordion Tab Change Event</h3>
<p-accordion [multiple]="true" (onOpen)="onOpen()">
<p-accordionTab header="Complete Interview Preparation">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/complete-interview-preparation-thumbnail.png?v=19265"
height="300" width="350" alt="gfg" />
</p-accordionTab>
<p-accordionTab header="System Design">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/system-design-live-thumbnail.png?v=19265"
height="300" width="350" alt="gfg" />
</p-accordionTab>
<p-accordionTab header="C++ STL Self-Paced">
<img src=
"https://media.geeksforgeeks.org/img-practice/banner/cpp-stl-thumbnail.png?v=19265"
height="300" width="350" alt="gfg"
/>
</p-accordionTab>
</p-accordion>
</div>
JavaScript
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
onOpen(){
alert("Accordion is Opened")
}
}
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 { AccordionModule } from 'primeng/accordion';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
AccordionModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
Output:
Reference: https://primefaces.org/primeng/accordion
Similar Reads
Angular PrimeNG Accordion Events 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 Events of Accordion component in Angular PrimeNG. Accordion component
3 min read
Angular PrimeNG Accordion 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 Accordion Component in Angular PrimeNG. We will also le
5 min read
Angular PrimeNG Accordion Default 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 Accordion Default in Angular PrimeNG, along with underst
4 min read
Angular PrimeNG Table Change Detection 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. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
7 min read
Angular PrimeNG Accordion Disabled 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 Accordion Disabled in Angular PrimeNG, along with unders
3 min read
Angular PrimeNG Accordion Templates Angular PrimeNG is a UI component library built by PrimeTek to help out Angular developers for easing the process of developing consistent and scalable web interfaces in less time. In this article, we will talk about Accordion Templates in Angular PrimeNG. The Accordion Component displays the conten
3 min read
Angular PrimeNG Accordion Lazy Loading 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 Accordion Lazy Loading in Angular PrimeNG. The Accordio
3 min read
Angular PrimeNG Accordion Styling 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 the Angular PrimeNG Accordion Styling. An Accordion Component is used t
3 min read
Angular PrimeNG Accordion Selected 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 Accordion Selected in Angular PrimeNG, along with unders
4 min read
Angular PrimeNG Accordion Multiple 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 Accordion Multiple in Angular PrimeNG, along with unders
3 min read