Open In App

Angular PrimeNG Menubar Custom Content

Last Updated : 17 Oct, 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 know how to use Menubar Custom Content in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The Menubar component is used to make a menu list in the form of a horizontal bar.

Angular PrimeNG Menubar Custom Content properties:

  • model: It is an array of menu items. It accepts the array data type as input & the default value is null.

 

Syntax:

<p-menubar [model]="...">
    ...
</p-menubar>

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:

 

To run the above file run the below command:

ng serve --save

Example 1: Below is the example that illustrates the use of Angular PrimeNG Menubar Custom Content using search and button.

  • app.component.html:

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h5>
    PrimeNG Menubar Custom Content
</h5>
  
<p-menubar [model]="gfg">
    <input type="text" 
        pInputText placeholder="type here..." />
    <button pButton label="Log In">
    </button>
</p-menubar>


  • 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',
                items: [
                    {
                        label: 'HTML 1'
                    },
                    {
                        label: 'HTML 2'
                    }
                ]
            },
            {
                label: 'Angular',
  
                items: [
                    {
                        label: 'Angular 1'
                    },
                    {
                        label: 'Angular 2'
                    }
                ]
            }
        ];
    }
}


  • app.component.ts:

Javascript




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';
import { InputTextModule } from 'primeng/inputtext';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MenubarModule,
        InputTextModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Example 2: Below is another example that illustrates the use of Angular PrimeNG Menubar Custom Content using dropdown and button.

  • app.component.html:

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h5>
    PrimeNG Menubar Custom Content
</h5>
  
<p-menubar [model]="gfg">
    <p-dropdown 
        [options]="gfgCourses" 
        optionLabel="name">
    </p-dropdown>
  
    <button pButton 
        label="Log In">
    </button>
</p-menubar>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
interface Courses {
    name: string;
    code: string;
}
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    gfg: MenuItem[];
    gfgCourses: Courses[];
  
    constructor() {
        this.gfgCourses = [
            { name: 'C++ STL', code: 'c++' },
            { name: 'DSA Self Paced', code: 'DSA' },
            { name: 'System Design', code: 'SD' },
        ];
    }
    ngOnInit() {
        this.gfg = [
            {
                label: 'HTML',
                items: [
                    {
                        label: 'HTML 1',
                    },
                    {
                        label: 'HTML 2',
                    },
                ],
            },
            {
                label: 'Angular',
  
                items: [
                    {
                        label: 'Angular 1',
                    },
                    {
                        label: 'Angular 2',
                    },
                ],
            },
        ];
    }
}


  • app.component.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { DropdownModule } from 'primeng/dropdown';
import { MenubarModule } from 'primeng/menubar';
import { InputTextModule } from 'primeng/inputtext';
import { ButtonModule } from 'primeng/button';
import { FormsModule } from '@angular/forms';
  
@NgModule({
    imports: [
        DropdownModule,
        FormsModule,
        BrowserModule,
        BrowserAnimationsModule,
        MenubarModule,
        InputTextModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

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



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

Similar Reads