Open In App

Angular PrimeNG Fieldset Templates

Last Updated : 31 Jan, 2023
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 different available Fieldset Templates in Angular PrimeNG.

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

This article will show the Fieldset Templating in Angular PrimeNG. The templates are used to put some content on some pre-structured containers. 

 

Fieldset templates are discussed below:

  • header: This is used to place the header of the Fieldset component.
  • content: This is used to place the content of the Fieldset component.

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 --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Fieldset Templates using the header pTemplate.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h3>Angular PrimeNG Fieldset Templates</h3>
  
<p-fieldset
    [toggleable]="true"
    [style]="{ 'text-align': 'center' }">
    <ng-template pTemplate="header">
          GeeksforGeeks
    </ng-template>
    It is a Computer Science portal.
</p-fieldset>


  • app.cmponent.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
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 code that illustrates the use of Angular PrimeNG Fieldset Templates using the content pTemplate.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h3>Angular PrimeNG Fieldset Templates</h3>
  
<p-fieldset
    [toggleable]="true"
    [style]="{ 'text-align': 'center' }">
    <ng-template pTemplate="header">
        GeeksforGeeks
    </ng-template>
    <ng-template pTemplate="content">
      <p>
          Welcome to Geeks For Geeks! 
          Billions of Users, Millions 
          of Articles Published, Thousands 
          Got Hired by Top Companies and 
          the numbers are still growing.
      </p>
    </ng-template>
</p-fieldset>


  • app.cmponent.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
  
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