Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda