javascript - Angular2从query.selectareas.js导入自调用的jQuery库给出运行时错误: jQuery is not defined

标签 javascript jquery angular typescript self-invoking-function

我在这里遇到了奇怪的问题,自调用函数需要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/

相关文章:

javascript - 服务器错误 (500)

javascript - 使用纯 JavaScript 将 HTML 表单序列化为 JSON

javascript - 获取具有定义类型的 JSON 对象长度

javascript - XmlhttpRequest 获取重定向链接?

angular - 与 React/Angular 的跨浏览器兼容性

jquery - 如何使用 angular4 在组件标签中设置粗体和斜体属性

javascript - JSON 参数大小限制

javascript - 如何在angular的$http中添加ajax的dataType属性?

html - 如何内联设置两个div

javascript - angular 2 Material 输入默认焦点移除