Skip to content
Related Articles

Related Articles

Angular PrimeNG Fieldset Component

Improve Article
Save Article
Like Article
  • Last Updated : 07 Oct, 2021

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 Fieldset component in Angular PrimeNG. We will also learn about the properties, events & styling along with their syntaxes that will be used in the code.

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

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.
  • collapsed: It defines the default visibility state of the content. It is of boolean data type, the default value is false.
  • style: It is an inline style of the fieldset. It is of string data type, the default value is null.
  • styleClass: It is the style class of the fieldset. It is of string data type, the default value is null.
  • transitionOptions: It is the transition option of the animation. It is of string data type, the default value is 400ms cubic-bezier(0.86, 0, 0.07, 1).

Event:

  • onBeforeToggle: It is a callback that is fired before content toggle.
  • onAfterToggle: It is a callback that is fired after content toggle.

 

Styling:

  • p-fieldset: It is the fieldset element.
  • p-fieldset-toggleable: It is the toggleable fieldset element.
  • p-fieldset-legend: It is the legend element.
  • p-fieldset-content: It is the content element.

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 is the basic example that illustrates how to use the Fieldset component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Fieldset Component</h5>
<p-fieldset legend="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-fieldset>

app.component.ts




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
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 { FieldsetModule } from "primeng/fieldset";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            FieldsetModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Example 2: In this example, we will know how to use the toggleable property in the Fieldset component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Fieldset Component</h5>
<p-fieldset legend="Angular PrimeNG" toggleable="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-fieldset>

app.component.ts




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
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 { FieldsetModule } from "primeng/fieldset";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            FieldsetModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!