Angular UI Components Documentation

Angular Menu Component

The Menu component for Angular represents a menu widget that makes it easy to add menus to your website or web application.

1. Installation

The easiest way to get started with jQWidgets UI for Angular is to use the Angular CLI Tool. To scaffold your project structure, follow its installation instructions.

npm install -g @angular/cli
ng new jqwidgets-project
cd jqwidgets-project

Install jQWidgets

jQWidgets Angular UI comes packaged with Angular CLI schematics to make creating Angular applications easier. Schematics are included with both @angular/cdk and jqwidgets-ng. Once you install the npm packages, they will be available through the Angular CLI.

Angular CLI supports the addition of packages through the ng add command. The ng add command provides faster and more user-friendly package installation. To install the jQWidgets UI for Angular package, use ng add and add the name of the NPM package:

ng add jqwidgets-ng

Alternatively, you can use the standard installation (Manual Setup)

jQWidgets UI for Angular is distributed as jqwidgets-ng NPM package

  1. Download and install the package.
    npm install jqwidgets-ng
  2. Adding CSS reference

    The following CSS file is available in ../node_modules/jqwidgets-ng/ package folder. This can be referenced in [src/styles.css] using following code.

    @import 'jqwidgets-ng/jqwidgets/styles/jqx.base.css';

    Another way to achieve the same is to edit the angular.json file and in the styles add the style.

    "styles": [
    	"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css"
    ]
    

2. Add the HTML for jQWidgets component in src/app/app.component.html

app.component.html


<div #jqxWidget style="height: 300px;">
  <jqxMenu [theme]="'fluent'" #menuReference [width]="getWidth()" [height]="30">
    <ul>
      <li><a href="#Home">Home</a></li>
      <li>
        Solutions
        <ul style="width: 250px;">
          <li><a href="#Education">Education</a></li>
          <li><a href="#Financial">Financial services</a></li>
          <li><a href="#Government">Government</a></li>
          <li><a href="#Manufacturing">Manufacturing</a></li>
          <li type="separator"></li>
          <li>
            Software Solutions
            <ul style="width: 220px;">
              <li><a href="#ConsumerPhoto">Consumer photo and video</a></li>
              <li><a href="#Mobile">Mobile</a></li>
              <li><a href="#RIA">Rich Internet applications</a></li>
              <li><a href="#TechnicalCommunication">Technical communication</a></li>
              <li><a href="#Training">Training and eLearning</a></li>
              <li><a href="#WebConferencing">Web conferencing</a></li>
            </ul>
          </li>
          <li><a href="#">All industries and solutions</a></li>
        </ul>
      </li>
      <li>
        Products
        <ul>
          <li><a href="#PCProducts">PC products</a></li>
          <li><a href="#MobileProducts">Mobile products</a></li>
          <li><a href="#AllProducts">All products</a></li>
        </ul>
      </li>
      <li>
        Support
        <ul style="width: 200px;">
          <li><a href="#SupportHome">Support home</a></li>
          <li><a href="#CustomerService">Customer Service</a></li>
          <li><a href="#KB">Knowledge base</a></li>
          <li><a href="#Books">Books</a></li>
          <li><a href="#Training">Training and certification</a></li>
          <li><a href="#SupportPrograms">Support programs</a></li>
          <li><a href="#Forums">Forums</a></li>
          <li><a href="#Documentation">Documentation</a></li>
          <li><a href="#Updates">Updates</a></li>
        </ul>
      </li>
      <li>
        Communities
        <ul style="width: 200px;">
          <li><a href="#Designers">Designers</a></li>
          <li><a href="#Developers">Developers</a></li>
          <li><a href="#Educators">Educators and students</a></li>
          <li><a href="#Partners">Partners</a></li>
          <li type="separator"></li>
          <li>
            By resource
            <ul>
              <li><a href="#Labs">Labs</a></li>
              <li><a href="#TV">TV</a></li>
              <li><a href="#Forums">Forums</a></li>
              <li><a href="#Exchange">Exchange</a></li>
              <li><a href="#Blogs">Blogs</a></li>
              <li><a href="#Experience Design">Experience Design</a></li>
            </ul>
          </li>
        </ul>
      </li>
      <li>
        Company
        <ul style="width: 180px;">
          <li><a href="#About">About Us</a></li>
          <li><a href="#Press">Press</a></li>
          <li><a href="#Investor">Investor Relations</a></li>
          <li><a href="#CorporateAffairs">Corporate Affairs</a></li>
          <li><a href="#Careers">Careers</a></li>
          <li><a href="#Showcase">Showcase</a></li>
          <li><a href="#Events">Events</a></li>
          <li><a href="#ContactUs">Contact Us</a></li>
          <li><a href="#Become an affiliate">Become an affiliate</a></li>
        </ul>
      </li>
    </ul>
  </jqxMenu>
  <br />
  <div style="margin-left: 60px;  margin-top: 120px;">
    <div style="font-size: 16px; font-family: Verdana Arial;">
      Settings
    </div>
    <div style="margin-top: 20px; font-size: 14px; font-family: Verdana Arial; float: left;">
      <jqxCheckBox [theme]="'fluent'" (onChange)="animationOnChange($event)"
                   [width]="150" [height]="20" [checked]="true">
        Enable Animation
      </jqxCheckBox>
      <div style="margin-top: 20px;">
        <jqxCheckBox [theme]="'fluent'" style="margin-top: 20px;" (onChange)="disabledOnChange($event)"
                     [width]="150" [height]="20" [checked]="false">
          Disabled
        </jqxCheckBox>
      </div>
    </div>
    <div style="margin-top: 20px; margin-left: 60px; font-size: 14px; font-family: Verdana Arial; float: left;">
      <jqxCheckBox [theme]="'fluent'" (onChange)="hoverOnChange($event)"
                   [width]="150" [height]="20" [checked]="true">
        Enable Hover
      </jqxCheckBox>
      <div style="margin-top: 20px;">
        <jqxCheckBox [theme]="'fluent'" (onChange)="openOnChange($event)"
                     [width]="150" [height]="20" [checked]="true">
          Auto Open
        </jqxCheckBox>
      </div>
    </div>
    <div style="margin-top: 20px; margin-left: 60px; font-size: 14px; font-family: Verdana Arial; float: left;">
      <jqxCheckBox [theme]="'fluent'" (onChange)="topLevelArrowsOnChange($event)"
                   [width]="200" [height]="20">
        Show Top-Level Arrows
      </jqxCheckBox>
    </div>
  </div>
</div>	

3. Setup Component Logic

app.component.ts


import { Component, ViewChild, ElementRef } from '@angular/core';

import { jqxCheckBoxComponent, jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
import { jqxMenuModule, jqxMenuComponent } from 'jqwidgets-ng/jqxmenu';
@Component({
    selector: 'app-root',
    imports: [jqxMenuModule, jqxCheckBoxModule],
    standalone: true,
    templateUrl: './app.component.html'
})

export class AppComponent {
    @ViewChild('menuReference') myMenu: jqxMenuComponent;

    getWidth(): any {
        if (document.body.offsetWidth < 600) {
            return '90%';
        }

        return 600;
    }

    animationOnChange(event: any): void {
        let value = event.args.checked;
        // enable or disable the menu's animation.
        if (!value) {
            this.myMenu.setOptions
                ({
                    animationShowDuration: 0,
                    animationHideDuration: 0,
                    animationShowDelay: 0
                });
        }
        else {
            this.myMenu.setOptions
                ({
                    animationShowDuration: 300,
                    animationHideDuration: 200,
                    animationShowDelay: 200
                });
        }
    }
    disabledOnChange(event: any): void {
        let value = event.args.checked;
        // enable or disable the menu
        if (!value) {
            this.myMenu.disabled(false);
        }
        else {
            this.myMenu.disabled(true);
        }
    }
    hoverOnChange(event: any): void {
        let value = event.args.checked;
        // enable or disable the menu's hover effect.
        if (!value) {
            this.myMenu.enableHover(false);
        }
        else {
            this.myMenu.enableHover(true);
        }
    }
    openOnChange(event: any): void {
        let value = event.args.checked;
        // enable or disable the opening of the top level menu items when the user hovers them.
        if (!value) {
            this.myMenu.autoOpen(false);
        }
        else {
            this.myMenu.autoOpen(true);
        }
    }
    topLevelArrowsOnChange(event: any): void {
        let value = event.args.checked;
        // enable or disable the top level arrows.
        if (!value) {
            this.myMenu.showTopLevelArrows(false);
        }
        else {
            this.myMenu.showTopLevelArrows(true);
        }
    }
}

Summary

jQWidgets UI for Angular provides an easy way to integrate robust UI components into your Angular project. By using either the ng add command or manual setup, you can quickly get started. Once the setup is complete, you can add the desired jQWidgets components and configure them in your Angular components to match your application requirements.

Menu API

API Reference of the jQWidgets Menu component for Angular: Menu API