2017-02-24 59 views
0

我想在我的Aurelia附加函數中調用jQuery。每當jQuery命令運行,我得到這個錯誤:解決「未處理的拒絕類型錯誤:jquery_1.default不是函數」

未處理的拒絕TypeError:jquery_1.default不是一個函數。

這裏是我的app.ts代碼:

import {Redirect, NavigationInstruction, RouterConfiguration} from 'aurelia-router'; 
    import 'semantic'; 
    import $ from 'jquery'; 

    export class App { 
     configureRouter(config: RouterConfiguration): void { 
     config.title = 'TrackRack'; 
     config.options.hashChange = false; 
     config.options.root = '/'; 
     config.map([ 
      { route: ['home'], name: 'home', moduleId: 'views/home' }, 
      { route: '', name: 'home2', moduleId: 'views/home'} 
     ]); 
     } 
     attached() { 
      $('.nav_menu').visibility({ 
      type: 'fixed' 
      }); 
     } 
    } 

這裏是我的配置:

  { 
       "name": "jquery", 
       "path": "../node_modules/jquery/dist", 
       "main": "jquery.js" 
       }, 
       { 
       "name": "semantic", 
       "path": "../node_modules/semantic-ui/dist", 
       "main": "semantic.js", 
       "resources": [ 
        "semantic.min.css" 
       ] 
      } 

回答

1

所有你需要在你的aurelia.json做的是

"jquery"

不需要比jQuery更復雜。

此外,請注意,您可以在視圖中使用ref自定義屬性來獲取對視圖中元素的引用。您可以將此參考傳遞給jQuery,而不是搜索元素。

app.html

<template> 
    ... 
    <nav ref="navMenu"> 
    ... 
    </nav> 
    ... 
</template> 

app.ts

$(this.navMenu)).visibility({ 
    type: 'fixed' 
}); 
+2

除了這個,我有我的導入改變這種一切正常工作==>進口*作爲$從'jquery' –

相關問題