Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
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 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda