What is the reason for the error since JQuery is being imported

0

I'm using Materialize along with Angular, however the menu dropdown is not working.

With the following error:

  

Uncaught TypeError: $ (...). dropdown is not a function   at funcoes.js: 6

The funcoes.js file has the following line of code only:

$(".dropdown-trigger").dropdown()
    
asked by anonymous 21.06.2018 / 16:02

2 answers

0

Review if all required libraries have been imported and are in the correct order.

  • jQuery
  • Materialize.js
  • Materialize.css

Here is an example that works:

$(".dropdown-trigger").dropdown();
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script><linkrel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script><aclass='dropdown-triggerbtn'href='#'data-target='dropdown1'>Importetodsasbibliotecas\/</a><ulid='dropdown1'class='dropdown-content'><li><ahref="#!">jQuery</a></li>
  <li><a href="#!">materialize.js</a></li>
  <li><a href="#!">materialize.css</a></li>
</ul>
    
21.06.2018 / 16:21
0

no angular-cli.json should also be imported

  "scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "../node_modules/bootstrap-notify/bootstrap-notify.js",
    "../node_modules/chartist/dist/chartist.js"
  ],

and set the $ in app.module.ts

import * as $ from 'jquery';
    
25.06.2018 / 01:35