2016-08-17 62 views
0

我想知道如何将jquery插入到组件中。例如如何将jQuery插入到Angular 1.5组件中

在我webpack.conf文件:

new webpack.ProvidePlugin({ 
    $: "jquery", 
    jQuery: "jquery", 
    "window.jQuery": "jquery" 
}) 

在我的组件文件:

module.exports = { 
templateUrl: 'app/example.html', 
controller: ['$', exampleController] 
}; 

function exampleController(){ 
console.log('exampleController'); 
}; 

堆栈:角1.5,JavaScript中,NPM和的WebPack

回答

2

除非你把jQuery打包成一个ngular模块,您不会将其注入到使用Angular注入的控制器中。为了在带有webpack的角度组件中使用jQuery,只需要将它置于您正在使用的任何文件的顶部:

var $ = require('jquery'); 
+0

Thanks @ryanlutgen –