Angular PrimeNG Menubar Component - GeeksforGeeks

08 Sep, 2021
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 know how to use the Menubar component in Angular PrimeNG. We will also learn about the properties, styling along with their syntaxes that will be used in the code.
Menubar component: It is used to make a menu list in the form of a horizontal bar.
Properties:
model: It is an array of menu items. It accepts the array data type as input & the default value is null.
style: It is an inline style of the component. It is of string data type & the default value is null.
styleClass: It is used to set the style class of the component. It is of string data type & the default value is null.
baseZIndex: It is used to set base zIndex value to use in layering. It accepts the number data type as input & the default value is 0.
autoZIndex: It is used to specify whether to automatically manage the layering. It accepts the boolean data type as input & the default value is true.
autoDisplay: It is used to specify whether to show a root submenu on mouseover. It accepts the boolean data type as input & the default value is false.
Styling:
p-menubar: It is the container element.
p-menu-list: It is a list element.
p-menuitem: It is the menuitem element.
p-menuitem-text: It is the label of a menuitem.
p-menuitem-icon: It is the icon of a menuitem.
p-submenu-icon: It is the arrow icon of a submenu.
 
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: This is the basic example that illustrates how to use the Menubar component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG MenuBar Component</h5><p-menubar [model]="gfg"></p-menubar>
app.module.ts
import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BrowserAnimationsModule }     from '@angular/platform-browser/animations';  import { AppComponent } from './app.component';import { MenubarModule } from 'primeng/menubar';@NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             MenubarModule],  declarations: [AppComponent],  bootstrap: [AppComponent]})export class AppModule {}
app.component.ts
import { Component } from '@angular/core';import { MenuItem } from 'primeng/api';  @Component({  selector: 'my-app',  templateUrl: './app.component.html'})export class AppComponent {  gfg: MenuItem[];    ngOnInit() {    this.gfg = [      {        label: 'HTML',        items: [          {            label: 'HTML 1'          },          {            label: 'HTML 2'          }        ]      },      {        label: 'Angular',          items: [          {            label: 'Angular 1'          },          {            label: 'Angular 2'          }        ]      }    ];  }}
Output:
Reference: https://primefaces.org/primeng/showcase/#/menubar
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular 10 (blur) Event
Angular PrimeNG Messages Component
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?