Open In App

Angular PrimeNG TabMenu Scrollable

Last Updated : 30 Aug, 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 see how to use the TabMenu Scrollable 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. The Scrollable represents the scroll can be in the horizontal direction, that contains large number of tabs with left & right arrow to scroll it, or simply contains the default tabs that need to be changed it manually.

Syntax:

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

Angular PrimeNG TabMenu Scrollable properties:

  • model: It is an array of menu items. It accepts the array as an input data type & the default value is null.
  • scrollable: It is used to specify that the TabMenu items should be scrollable. It is a boolean type. The default value is false. 
  • 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.

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:

Project Structure

  • Run the below command to see the output:
ng serve --open

Example 1: Below is the example illustrates the basic usage of Angular PrimeNG TabMenu Scrollable.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG TabMenu Scrollable</h5>
  
    <div class="card">
        <p-tabMenu [model]="gfg" 
                   [scrollable]="true">
        </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 = Array.from(
      {
        length: 10,
      },
      (_, i) => ({
        label: `Geek ${i + 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:

 

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

app.component.html




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

 

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



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

Similar Reads