2017-02-24 54 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' –