Open In App

Angular PrimeNG Accordion Disabled

Last Updated : 06 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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 understanding the properties, & their syntaxes that will be used in the code.

The Accordion component is used to display a section of custom content in tabs. Enabling the disabled=”true” attribute disables the open or close behavior of the tab.

Syntax:

<p-accordion">
    <p-accordionTab header="..." 
         [disabled]="true">
           ...
        </p-accordionTab>
        ...
</p-accordion>

 

Angular PrimeNG Accordion Disabled properties:

  • header: It specifies the title of the tab. It is of string data type & the default value is null.
  • disabled: It defines whether the tab can be selected. It is of the boolean data type & the default value is false.

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: Below is the example that illustrates the use of the Angular PrimeNG Accordion Disabled.

app.component.html




<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Accordion Disabled</h5>
<p-accordion>
    <p-accordionTab header="Angular PrimeNG" [disabled]="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="React JS">
        <p>
            React uses a declarative paradigm that makes it
            easier to reason about your application and aims
            to be both efficient and flexible. It designs simple
            views for each state in your application, and React
            will efficiently update and render just the right
            component when your data changes.
        </p>
    </p-accordionTab>
</p-accordion>


app.component.ts




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
  
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
   providers: [MessageService],
})
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 { 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 example that illustrates the use of the Angular PrimeNG Accordion Disabled.

app.component.html




<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Accordion Disabled</h5>
<p-accordion>
    <p-accordionTab header="Course 1">
        <img src=
            height="300" width="350" alt="gfg" />
    </p-accordionTab>
    <p-accordionTab header="Course 2(disabled)" [disabled]="true">
        <img src=
            height="300" width="350" alt="gfg" />
    </p-accordionTab>
</p-accordion>


app.component.ts




import { Component } from '@angular/core';
import { MessageService } from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  providers: [MessageService],
})
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 { 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://primefaces.org/primeng/accordion



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads