jquery - 在自定义 Angular 6+ 库中使用 jQuery
问题描述
EDIT2
我觉得我编写一个独立的角度库供其他人使用的方法是错误的?
我的第一个想法是编写一个 npm 模块,但它必须是私有的并且不能发布 - 这会工作/容易吗?
我的方法错了吗?
如何在我的 Angular 6+ 库中使用 jQuery?
我创建了一个图书馆
ng generate library nodeeditor --prefix=lib
然后添加了一个 jQuery npm 模块到它
cd projects/nodeeditor
npm i --save jquery
但是当说明
import * as jQuery from 'jquery/dist/jquery.min.js'
在 nodeeditor.component.ts 中(就像我在 Angular 项目中所做的那样,仅在绝对必要时)
ng build nodeeditor
给我
构建错误无法调用命名空间('jQuery')
有人知道吗?
EDIT1
生成的文件夹结构如下所示
解决方案
npm install jquery --save
.angular-cli.json or angular.json:
"scripts": [
"node_modules/jquery/dist/jquery.js"
]
Import jquery file module.ts file
import * as $ from 'jquery';
to check jquery included in our application write $ in the browser console
推荐阅读
- java - 未能执行目标 org.openjfx:javafx-maven-plugin:0.0.4。我从 Fxml 文件开始,我无法将它们附加到控制器
- preact - 如果返回的 vdom 完全相同,则保留第一个渲染道具
- javascript - 具有多个条件的 Javascript for 循环不起作用
- python - 如何在 PyTorch 中完成多维花式索引?
- magento - 如何获取在 Magento 2 中创建的电子邮件模板订单状态 url
- python - 硒元素数据提取
- node.js - 用一行 Javascript 更新数组
- python - 如何在 Qt Designer 制作的 GUI 中添加最小化/最大化按钮?
- python - 如何让 Python 从我的 Discord 机器人的 .txt 文档中读取列表
- python-3.x - Python如何在列表中从文件到字典