Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Define metisMenu in Webpack using angular

I have created project using 'jhipster' and it is Angular 4 project. It is using Webpack and 'yarn'. I installed metisMenu for my requirement, it is there in package.json file. I defined metisMenu in vendor.ts and also in 'webpack' but it is showing error jQuery(...).metisMenu is not a function.

I am using Webpack for first time. What is the exact way to define it in Webpack ?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I imported metisMenu directly in required Component and it solved my problem.

over 4 years ago · Santiago Trujillo Report

0

Thanks to Jeeten Parmar I was able to solve this using the following code in my component where I was referencing it:

import 'metismenu';
...

// you can call this inside ngAfterViewInit() in your component
jQuery('#side-menu').metisMenu();

Hope this helps

over 4 years ago · Santiago Trujillo Report

0

If you used angular cli with angular >2 -> 4, you can declared in .angular-cli.json like this :

 "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/metismenu/dist/metisMenu.js"
        [... others jquery plugin ...]
],

And in your component, you declare jquery like this :

declare let $: any;

You must use ngAfterViewInit for waiting the "dom ready" event. Finaly, you have a component like this :

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

declare let $: any;

@Component({ 
    [...]
    ngAfterViewInit() {
         this.menuElement = this._elementRef.nativeElement.querySelector('#side-menu');
         (<any>$(this.menuElement)).metisMenu();
    }

be careful, if you import jquery like this :

import * as $ from 'jquery';

$ is a new instance of jquery so MetisMenu will not be implemented inside and jquery object is replaced by the new instance in global

Enjoy :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!