我在这里遇到了奇怪的问题,自调用函数需要jquery。
这是我想使用的库:jquery.selectareas.js
这是代码
import * as jQuery from 'jquery';
import "query.selectareas.js"
Runtime Error : jQuery is not defined at this line
我尝试使用所有不同的组合导入 JQ
//import * as $ from 'jquery';
//import * as jQuery from 'jquery';
//window['$'] = window['jQuery'] = $;
//import "jquery"
据我所知,导入的 jQuery 应该在 jquery.selectareas.js 内可用导入时的范围,因为它们将在同一范围内。
注意:jquery工作我在所有导入语句之后使用了它
最佳答案
您可能需要imports-loader
import "imports-loader?jQuery=jquery!query.selectareas.js"
这会将 jQuery
变量注入(inject)到您导入的模块中
关于javascript - Angular2从query.selectareas.js导入自调用的jQuery库给出运行时错误: jQuery is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46521438/