Open In App

Angular PrimeNG TabMenu Properties

Last Updated : 01 Nov, 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. In this article, we will learn how to use TabMenu Properties 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.

Angular PrimeNG TabMenu 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 defines the default active menu item. It accepts the menu item as an input type & the default value is null.
  • style: It sets the inline style of the component. It accepts the string as an input data type & the default value is null.
  • styleClass: It is the style class of the component. It accepts the string as an input data type & the default value is null.
  • scrollable: It displays buttons to scroll the tab list on each side of the tab headers when enabled. It is of boolean type and 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: After the complete installation, it will look like the following

 

Steps to run the application: To run the above file run the below command:

ng serve --save

Example 1: This is the basic example that shows how to use the Angular PrimeNG TabMenu Properties.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG TabMenu Properties</h5>
<p-tabMenu [model]="gfg"></p-tabMenu>


  • app.component.ts:

Javascript




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: 'AngularJS',
            },
            {
                label: 'ReactJS',
            },
            {
                label: 'PrimeNG',
            },
        ];
    }
}


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


Output:

 

Example 2: This is another basic example that shows how to use the Angular PrimeNG TabMenu Properties.

  • app.component.html:

HTML




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


  • app.component.ts:

Javascript




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 = Array.from(
            {
              length: 10,
            },
            (_, i) => ({ label: `Geek ${i + 1}`})
        );
    }
}


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


Output:

 

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads