Open In App

Angular PrimeNG Fieldset Toggleable

Last Updated : 19 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. This article will show us how to use the Fieldset Toggleable in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The Fieldset Component is a grouping component that takes a header along with some content associated with that header having a toggle feature.

Syntax:

<p-fieldset 
    legend="...." 
    [toggleable]="true">
    <p>....</p>
</p-fieldset>

 

Angular PrimeNG Fieldset Toggleable Properties:

  • legend: It is the header text of the fieldset. It is of string data type, the default value is null.
  • toggleable: It specifies whether the content can be toggled by clicking the legend. It is of 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:

ng serve --open

Example 1: Below is the basic example demonstrating the use of Angular PrimeNG Fieldset Togglable.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>
    Angular PrimeNG Fieldset Toggleable
</h5>
  
<p-fieldset 
    legend="GeeksforGeeks" 
    [toggleable]="true">
    <p>
           Welcome to GeeksforGeeks.
        It is a Computer Science
        portal for all Geeks.
    </p>
</p-fieldset>


  • app.component.ts:

Javascript




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


  • 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 { FieldsetModule, } from 'primeng/fieldset';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FieldsetModule,
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Example 2: Below is another example that demonstrates the use of Angular PrimeNG Fieldset Togglable using an image.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Fieldset Toggleable</h5>
  
<p-fieldset 
    legend="GeeksforGeeks" 
    [toggleable]="true">
    <p>
        <img alt="gfg" src=
    </p>
</p-fieldset>


  • app.component.ts:

Javascript




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


  • 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 { FieldsetModule, } from 'primeng/fieldset';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FieldsetModule,
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/fieldset



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads