Open In App

Angular PrimeNG Menubar Templates

Last Updated : 01 Feb, 2023
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 about Angular PrimeNG Menubar Templates

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

Angular PrimeNG Menubar Templates:

The templates are used to put some content on some pre-structured containers. Menubar templates are discussed below 

  • start: This is used for the start template
  • end: This is used for the end template

Syntax:

<p-menubar [model]="...">
    <ng-template pTemplate="..." >
         .......
    </ng-template>
</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:

 

Steps to run the application: Run the below command to see the output.

ng serve --save

Example 1: In this example, we will learn about the start template.

  • app.component.html:

HTML




<div style="width:50%">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>Angular PrimeNG MenuBar Templates </h2>
      
      <p-menubar [model]="gfg">
      <ng-template pTemplate="start" >
         I am Start Template
      </ng-template>
    </p-menubar>
</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 = [
            {
                label: 'HTML',
                items: [
                  {
                      label: 'HTML 1'
                  },
                  {
                      label: 'HTML 2'
                  }
                ]
            },
            {
                label: 'Angular',
  
                items: [
                  {
                      label: 'Angular 1'
                  },
                  {
                      label: 'Angular 2'
                  }
                ]
            }
        ];
    }
}


  • app.module.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';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MenubarModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}


Output:

 

Example 2: In this example, we will learn about the end template

  • app.component.html:

HTML




<div style="width:50%">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>Angular PrimeNG MenuBar Templates </h2>
    <p-menubar [model]="gfg">
        <ng-template pTemplate="end" >
             I am End Template
        </ng-template>
    </p-menubar>
</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 = [
            {
                label: 'HTML',
                items: [
                    {
                        label: 'HTML 1'
                    },
                    {
                        label: 'HTML 2'
                    }
                ]
            },
            {
                label: 'Angular',
  
                items: [
                    {
                        label: 'Angular 1'
                    },
                    {
                        label: 'Angular 2'
                    }
                ]
            }
        ];
    }
}


  • app.module.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';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MenubarModule
    ],
    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