Is it possible to use Materializecss without jQuery?

风格不统一 提交于 2020-01-14 07:31:32

问题


I would like to use materializecss without jQuery. For example, I want to do the following without the use of jQuery:

$('.chips-initial').material_chip({
    data: [{
      tag: 'Apple',
    }, {
      tag: 'Microsoft',
    }, {
      tag: 'Google',
    }],
  });

Thanks


回答1:


Starting with Materialize 1.0.0, jQuery is not a dependency anymore.

See https://medium.com/@materializecss/materialize-to-1-0-and-beyond-e0233b8ac15

Previous releases still rely on jQuery. Alternatively you can use Cash by Ken Wheeler.




回答2:


Since version 1.0.0 you can.

const elem = document.querySelector('.chips');
const instance = M.Chips.init(elem, options);

List of possible options for the chips.

For Angular2+ you'll need:

npm install materialize-css

In package.json

"dependencies": {
    "materialize-css": "^1.0.0-alpha.4",
}

or later version.

In .angular-cli.json

  "styles": [
    "../node_modules/materialize-css/dist/css/materialize.css"
  ],
  "scripts": [
    "../node_modules/materialize-css/dist/js/materialize.js"
  ],

And to be able to use M object in your components, simply add to the imports

declare const M: any;


来源:https://stackoverflow.com/questions/42353193/is-it-possible-to-use-materializecss-without-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!