Open In App

Angular PrimeNG TabMenu Default

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 TabMenu Default in Angular PrimeNG.

The TabMenu component is used to make a navigation bar that will display the nav items as a nav header ie., it is a menu in the form of tabs.

Syntax:

<p-tabMenu
    [model]="..."
    [activeItem]="...">
</p-tabMenu>

Angular PrimeNG TabMenu Default properties:

  • [model]: It is an array of menu items. It accepts the array as an input data type & the default value is null.
  • [activeItem]: It is used to define the item that is active by default.

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: After the complete installation, it will look like the following:

 

Run the below command to see the output:

ng serve --open

Example 1: Below is the example code that illustrates the use of Angular PrimeNG TabMenu Default.

app.component.html




<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG TabMenu Default</h5>
  
  <div class="card">
      <p-tabMenu 
           [model]="gfg">
      </p-tabMenu>
  </div>
</div>


app.component.ts




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
  
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
      this.gfg = [
      {
          label: 'HTML'
      },
      {
          label: 'CSS'
      },
      {
          label: 'JavaScript'
      },
      {
          label: 'AngularJS'
      },
      {
          label: 'AngularJS'
      },
      {
          label: 'ReactJS'
      },
      {
          label: 'PrimeNG'
      }
    ];
 }
}


app.module.ts




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 { MessageModule } from 'primeng/message';
import { TabMenuModule } from 'primeng/tabmenu';
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MessageModule,
    TabMenuModule,
    RouterModule.forRoot([
        {path:'',component: AppComponent},
    ])
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG TabMenu Default.

app.component.html




<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG TabMenu Default</h5>
  
  <div class="card">
    <p-tabMenu 
         [model]="gfg" 
         [activeItem]="activeItem">
    </p-tabMenu>
  </div>
</div>


app.component.ts




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  gfg: MenuItem[];
  activeItem: MenuItem;
  ngOnInit() {
    this.gfg = [
      {
        label: 'WhatsApp',
        icon: 'pi pi-whatsapp',
      },
      {
        label: 'LinkedIn',
        icon: 'pi pi-linkedin',
      },
      {
        label: 'Instagram',
        icon: 'pi pi-instagram',
      },
      {
        label: 'Slack',
        icon: 'pi pi-slack',
      },
    ];
    this.activeItem = this.gfg[1];
  }
}


app.module.ts




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 { MessageModule } from 'primeng/message';
import { TabMenuModule } from 'primeng/tabmenu';
  
@NgModule({
   imports: [
     BrowserModule,
     BrowserAnimationsModule,
     MessageModule,
     TabMenuModule,
     RouterModule.forRoot([
       {path:'',component: AppComponent},
     ])
   ],
   declarations: [ AppComponent ],
   bootstrap:    [ AppComponent ]
})
  
export class AppModule {}


Output:

 

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



Last Updated : 25 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads