Angular PrimeNG Menubar Templates
Last Updated :
01 Feb, 2023
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.
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 >
|
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'
}
]
}
];
}
}
|
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
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 >
|
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'
}
]
}
];
}
}
|
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
Share your thoughts in the comments
Please Login to comment...