Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Angular PrimeNG TabView Header Template

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 TabView Header Template in Angular PrimeNG.

Angular PrimeNG TabView Header Template is used to set the header of a tab. It supports templating to place custom HTML content instead of strings as well.

Syntax:

<p-tabPanel>
    <ng-template pTemplate="header">
        Content
    </ng-template>
</p-tabPanel>

 

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: Below is a simple example demonstrating the use of the Angular PrimeNG TabView Header Template.

  • app.component.html

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h4>
    Angular PrimeNG Tabview Header Template
</h4>
<p-tabView [(activeIndex)]="index">
    <p-tabPanel>
        <ng-template pTemplate="header">
            Coding
        </ng-template>
        <p>
            Code Here
        </p>
    </p-tabPanel>
    <p-tabPanel>
        <ng-template pTemplate="header">
            Web Technologies
        </ng-template>
        <p>
            Learn About Web Technologies
        </p>
    </p-tabPanel>
    <p-tabPanel>
        <ng-template pTemplate="header">
            Articles
        </ng-template>
        <p>
            Read some Tech Articles
        </p>
    </p-tabPanel>
</p-tabView>


  • app.component.ts

Javascript




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


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
  
import { TabViewModule } from 'primeng/tabview';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TabViewModule,
        ButtonModule,
        RouterModule.forRoot([{ path: '', component: AppComponent }]),
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }


Output:

 

Example 2: Below is another example demonstrating the use of the Angular PrimeNG TabView Header Template. In this example, we are using programmatic tabs with a header template.

  • app.component.html

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h4>
    Angular PrimeNG Tabview Header Template
</h4>
<div style="padding: .5em 0 1em 0">
    <p-button 
        (click)="index = 0
        label="Activate Coding Tab">
    </p-button>
    <br />
    <br />
  
    <p-button 
        (click)="index = 1
        label="Activate Web Technologies Tab">
    </p-button>
    <br />
    <br />
  
    <p-button 
        (click)="index = 2
        label="Activate Articles Tab">
    </p-button>
</div>
<p-tabView [(activeIndex)]="index">
    <p-tabPanel>
        <ng-template pTemplate="header">
            Coding
        </ng-template>
        <p>
            Code Here
        </p>
    </p-tabPanel>
    <p-tabPanel>
        <ng-template pTemplate="header">
            Web Technologies
        </ng-template>
        <p>
            Learn About Web Technologies
        </p>
    </p-tabPanel>
    <p-tabPanel>
        <ng-template pTemplate="header">
            Articles
        </ng-template>
        <p>
            Read some Tech Articles
        </p>
    </p-tabPanel>
</p-tabView>


  • app.component.ts

Javascript




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


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
  
import { TabViewModule } from 'primeng/tabview';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TabViewModule,
        ButtonModule,
        RouterModule.forRoot([{ path: '', component: AppComponent }]),
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }


Output:

 

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


My Personal Notes arrow_drop_up
Last Updated : 19 Oct, 2022
Like Article
Save Article
Similar Reads
Related Tutorials