Angular PrimeNG Accordion Animation Configuration
Last Updated :
30 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. This article will show us how to use the Accordion Animation Configuration in Angular PrimeNG.
Accordion component: It is used to display a section of custom content in tabs.
Angular PrimeNG Accordion Animation Configuration properties:
- transitionOptions: Transition options of the animation. It is of string data type & the default value is 400ms cubic-bezier(0.86, 0, 0.07, 1).
- header: It specifies the title of the tab. It is of string data type & the default value is null.
- selected: It defines if the tab is active. It is of the boolean data type & the default value is false.
- disabled: It defines whether the tab can be selected. It is of the boolean data type & the default value is false.
- cache: It specifies whether a lazy loaded panel should avoid getting loaded again on reselection. It is of the boolean data type & the default value is true.
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 --open
Example 1: In the below code, we will make use of the above syntax to demonstrate the Accordion Animation Configuration in Angular PrimeNG.
app.component.html:
HTML
< div style = "text-align: center;" >
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< p-accordion >
< p-accordionTab
header = "Header I"
[selected]="true"
[transitionOptions]="'3000ms'">
< p >GeeksforGeeks 1</ p >
</ p-accordionTab >
< p-accordionTab header = "Header II" >
< p >GeeksforGeeks 2</ p >
</ p-accordionTab >
< p-accordionTab header = "Header III" >
< p >GeeksforGeeks 3</ p >
</ p-accordionTab >
</ p-accordion >
</ div >
|
app.component.ts:
Javascript
import { Component } from "@angular/core" ;
import { MessageService } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
providers: [MessageService]
})
export class AppComponent {
activeState: boolean[] = [ true , false , false ];
constructor(private messageService: MessageService) {}
onTabClose(event) {
this .messageService.add({
severity: "info" ,
summary: "Tab Closed" ,
detail: "Index: " + event.index
});
}
onTabOpen(event) {
this .messageService.add({
severity: "info" ,
summary: "Tab Expanded" ,
detail: "Index: " + event.index
});
}
toggle(index: number) {
this .activeState[index] = ! this .activeState[index];
}
}
|
app.module.ts:
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 { ButtonModule } from "primeng/button" ;
import { AccordionModule } from "primeng/accordion" ;
import { ToastModule } from "primeng/toast" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
AccordionModule,
ButtonModule,
ToastModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
Output:
Â
Example 2: Below is another code, where we will make use of the above syntax to demonstrate the Accordion Animation Configuration in Angular PrimeNG.
app.component.html:
HTML
< div style = "text-align: center;" >
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< p-accordion >
< p-accordionTab header = "Header I" [selected]="true">
< p >GeeksforGeeks 1</ p >
</ p-accordionTab >
< p-accordionTab header = "Header II" >
< p >GeeksforGeeks 2</ p >
</ p-accordionTab >
< p-accordionTab header = "Header III" [transitionOptions]="'4000ms'">
< p >GeeksforGeeks 3</ p >
</ p-accordionTab >
</ p-accordion >
</ div >
|
app.compoennt.ts:
Javascript
import { Component } from "@angular/core" ;
import { MessageService } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
providers: [MessageService]
})
export class AppComponent {
activeState: boolean[] = [ true , false , false ];
constructor(private messageService: MessageService) {}
onTabClose(event) {
this .messageService.add({
severity: "info" ,
summary: "Tab Closed" ,
detail: "Index: " + event.index
});
}
onTabOpen(event) {
this .messageService.add({
severity: "info" ,
summary: "Tab Expanded" ,
detail: "Index: " + event.index
});
}
toggle(index: number) {
this .activeState[index] = ! this .activeState[index];
}
}
|
app.module.ts:
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 { ButtonModule } from "primeng/button" ;
import { AccordionModule } from "primeng/accordion" ;
import { ToastModule } from "primeng/toast" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
AccordionModule,
ButtonModule,
ToastModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
Output:
Â
Reference: https://www.primefaces.org/primeng/accordion
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...