簡體   English   中英

在Aurelia項目中找不到Materialise-css javascript函數

[英]Materialize-css javascript functions not found in Aurelia project

我創建了一個自定義屬性來控制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');
    }
}

此外,我還安裝了materialize-css:

jspm install npm:materialize-css

...並且我已經在main.ts導入了:

import materialize from 'materialize-css';

但是,每當具有material-select屬性的元素嘗試加載時,我都會得到以下控制台輸出:

ATTACHED
The attached element is: [object HTMLSelectElement]
Uncaught TypeError: $(...).material_select is not a function

如何從Aurelia中識別出materialize-css javascript函數?

卸載軟件包的npm版本,然后安裝github版本:

jspm uninstall npm:materialize-css
jspm install github:Dogfalo/materialize

通過安裝github版本,將使用程序包覆蓋,並將使用正確的依賴項(jquery + css)安裝該程序包。

然后,您將可以執行以下操作:

import $ from 'Dogfalo/materialize';

$('.foo').material_select();

注意:在合並此PR之前,上述步驟不起作用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM