Open In App

Angular PrimeNG MegaMenu Templates

Last Updated : 02 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 see how to use Angular PrimeNG MegaMenu Templates.

The MegaMenu component is a navigation component that is used to make a component with multiple numbers of the menu. The Templates are used to put some content on some pre-structured containers.

Angular PrimeNG MegaMenu Templates

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

Syntax

<p-megaMenu [model]="..." >
  <ng-template pTemplate="start/end">
 ...
  </ng-template>
    
</p-megaMenu>

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 1: This example describes the basic usage of the MegaMenu Templates in Angular PrimeNG by implementing the pTemplate attribute & setting its value as start.

  • app.component.html

HTML




<div>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG MegaMenu Templates
    </h2>
  
    <p-megaMenu [model]="gfg">
        <ng-template pTemplate="start">
            <input type="text" 
                   pInputText placeholder="I am pTemplate Start">
        </ng-template>
    </p-megaMenu>
</div>


  • app.component.ts

Javascript




import { Component } from '@angular/core';
import { MegaMenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    gfg: MegaMenuItem[] = [];
  
    ngOnInit() {
        this.gfg = [
            {
                label: 'GeeksforGeeks',
                items: [
                    [
                        {
                            label: 'AngularJS',
  
                        },
                        {
                            label: 'ReactJS',
  
                        }
                    ],
                    [
                        {
                            label: 'HTML',
  
                        },
                        {
                            label: 'PrimeNG',
  
                        }
                    ]
                ]
            },
  
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { TabViewModule } from "primeng/tabview";
import { AppComponent } from './app.component';
import { MegaMenuModule } from 'primeng/megamenu';
  
@NgModule({
    imports: [BrowserModule,
        BrowserAnimationsModule,
        MegaMenuModule, TabViewModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }


Output:

 

Example 2: In this example, we will be implementing pTemplate attribute & setting its value as end.

  • app.component.html

HTML




<div>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG MegaMenu Templates
    </h2>
  
    <p-megaMenu [model]="gfg">
        <ng-template pTemplate="end">
            <input type="text" 
                   pInputText placeholder="I am pTemplate end">
        </ng-template>
    </p-megaMenu>
</div>


  • app.component.ts

Javascript




import { Component } from '@angular/core';
import { MegaMenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    gfg: MegaMenuItem[] = [];
  
    ngOnInit() {
        this.gfg = [
            {
                label: 'GeeksforGeeks',
                items: [
                    [
                        {
                            label: 'AngularJS',
  
                        },
                        {
                            label: 'ReactJS',
  
                        }
                    ],
                    [
                        {
                            label: 'HTML',
  
                        },
                        {
                            label: 'PrimeNG',
  
                        }
                    ]
                ]
            },
  
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { TabViewModule } from "primeng/tabview";
import { AppComponent } from './app.component';
import { MegaMenuModule } from 'primeng/megamenu';
  
@NgModule({
    imports: [BrowserModule,
              BrowserAnimationsModule,
              MegaMenuModule, 
              TabViewModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }


Output:

 

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



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

Similar Reads