问题
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