Open In App

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 to display a section of custom content in tabs.



Angular PrimeNG Accordion Styling:

 



Syntax

<p-accordion>
    <p-accordionTab header="Header">
        Content 
    </p-accordionTab>
 </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:

 

Example 1: This example illustrates the use of the Angular PrimeNG Accordion Styling, where the first accordion is initially selected. Here, we have implemented the p-accordion and p-accordion-content.




<h1 style="color: green">
    GeeksforGeeks
</h1>
<h3>
    Angular PrimeNG Accordion Styling
</h3>
  
<p-accordion>
    <p-accordionTab header="Angular PrimeNG" 
                    [selected]="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-accordionTab>
    <p-accordionTab 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-accordionTab>
    <p-accordionTab 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-accordionTab>
</p-accordion>




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent { }




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: This is another example that illustrates the use of the Angular PrimeNG Accordion Styling by implementing the p-accordion-header.




<div style="width: 400px;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <h3>
        Angular PrimeNG Accordion Styling
    </h3>
  
    <div class="mb-4">
        <button pButton type="button" 
                        class="mr-3" 
                        label="Toggle Tab 1" 
                        (click)="toggleTab(0)">
        </button>
  
        <button pButton type="button" 
                        label="Toggle Tab 2" 
                        (click)="toggleTab(1)">
        </button>
    </div>
  
    <p-accordion [multiple]="true">
        <p-accordionTab header="AccordionTab 1 Header" 
                        [(selected)]="activeTabs[0]">
            This is the content of the Accordion Tab 1.
        </p-accordionTab>
        <p-accordionTab header="AccordionTab 2 Header" 
                        [(selected)]="activeTabs[1]">
            This is the content of the Accordion Tab 2.
        </p-accordionTab>
    </p-accordion>
</div>




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
})
  
export class AppComponent {
    activeTabs: boolean[] = [false, false];
  
    toggleTab(idx: number) {
        this.activeTabs[idx] =
            !this.activeTabs[idx];
    }
}




import { NgModule } from "@angular/core";
import { BrowserModule } 
    from "@angular/platform-browser";
import { HttpClientModule } 
    from "@angular/common/http";
import { BrowserAnimationsModule }
    from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { ButtonModule } from "primeng/button";
import { AccordionModule } from "primeng/accordion";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        HttpClientModule,
        ButtonModule,
        AccordionModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

Output:

 

Reference: http://primefaces.org/primeng/accordion


Article Tags :