[英]Materialize-css javascript functions not found in Aurelia project
I've created a custom attribute to control the lifecycle of a materilaize select
element: 我创建了一个自定义属性来控制materilaize
select
元素的生命周期:
import {customAttribute} from 'aurelia-templating';
import {inject} from 'aurelia-dependency-injection';
@customAttribute('material-select')
@inject(Element)
export class MaterialSelect {
element: Element = null;
constructor(element) {
this.element = element;
}
attached() {
console.log("ATTACHED");
console.log(`The attached element is: ${this.element}`);
$(this.element).material_select();
}
detached() {
console.log("DETACHED");
$(this.element).material_select('destroy');
}
}
Additionally, I've installed materialize-css with: 此外,我还安装了materialize-css:
jspm install npm:materialize-css
... and I've imported materilialize in main.ts
with: ...并且我已经在
main.ts
导入了:
import materialize from 'materialize-css';
But, whenever an element with the material-select
attribute tries to load I get this console output: 但是,每当具有
material-select
属性的元素尝试加载时,我都会得到以下控制台输出:
ATTACHED
The attached element is: [object HTMLSelectElement]
Uncaught TypeError: $(...).material_select is not a function
How do I get the materialize-css javascript functions to be recognized from within Aurelia? 如何从Aurelia中识别出materialize-css javascript函数?
Uninstall the npm version of the package and install the github version instead: 卸载软件包的npm版本,然后安装github版本:
jspm uninstall npm:materialize-css
jspm install github:Dogfalo/materialize
By installing the github version the package override will be used and the package will be installed with the correct dependencies (jquery + css). 通过安装github版本,将使用程序包覆盖,并将使用正确的依赖项(jquery + css)安装该程序包。
Then you'll be able to do this: 然后,您将可以执行以下操作:
import $ from 'Dogfalo/materialize';
$('.foo').material_select();
Note: the steps above will not work until this PR is merged 注意:在合并此PR之前,上述步骤不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.