Open In App

Angular PrimeNG MegaMenu Properties

Last Updated : 20 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 learn how to use MegaMenu Properties in Angular PrimeNG. 

The MegaMenu component is a navigation component that is used to make a component with multiple numbers of the menu.

Angular PrimeNG MegaMenu Properties:

  • model: It is an array of menuitems. It accepts the array data type as input & the default value is null.
  • orientation: It is used to define the orientation. It is of string data type & the default value is horizontal.
  • style: It is used to set the 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 the 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 is of boolean data type & the default value is true.

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 MegaMenu Properties using horizontal menus. 

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG MegaMenu Properties</h5>
<p-megaMenu [model]="gfg"></p-megaMenu>


  • 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",
                            items: [
                                { label: "AngularJS 1" },
                                { label: "AngularJS 2" }
                            ]
                        },
                        {
                            label: "ReactJS",
                            items: [
                                { label: "ReactJS 1" },
                                { label: "ReactJS 2" }
                            ]
                        }
                    ],
                    [
                        {
                            label: "HTML",
                            items: [{ label: "HTML 1" },
                                    { label: "HTML 2" }]
                        },
                        {
                            label: "PrimeNG",
                            items: [
                                { label: "PrimeNG 1" },
                                { label: "PrimeNG 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 { MegaMenuModule } from 'primeng/megamenu';
 
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MegaMenuModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
 
export class AppModule {}


Output:

 

Example 2: Below is another example that illustrates the use of Angular PrimeNG MegaMenu Properties using vertical menus. 

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG MegaMenu Properties</h5>
<p-megaMenu
    [model]="gfg"
    orientation='vertical'>
</p-megaMenu>


  • 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",
                            items: [
                                { label: "AngularJS 1" },
                                { label: "AngularJS 2" }
                            ]
                        },
                        {
                            label: "ReactJS",
                            items: [
                                { label: "ReactJS 1" },
                                { label: "ReactJS 2" }
                            ]
                        }
                    ],
                    [
                        {
                            label: "HTML",
                            items: [{ label: "HTML 1" }, { label: "HTML 2" }]
                        },
                        {
                            label: "PrimeNG",
                            items: [
                                { label: "PriemNG 1" },
                                { label: "PrimeNG 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 { MegaMenuModule } from 'primeng/megamenu';
 
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        MegaMenuModule],
    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