编辑2
我感觉我编写独立的 Angular 库供其他人使用的方法是错误的?
我的第一个想法是编写一个 npm 模块,但它必须是私有(private)的并且不能发布 - 这会工作/容易吗?
难道是我的方法不对?
如何在 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
给我
BUILD ERROR Cannot call a namespace ('jQuery')
有人知道吗?
编辑1
生成的文件夹结构如下所示
最佳答案
npm install jquery --save
.angular-cli.json 或 angular.json:
"scripts": [
"node_modules/jquery/dist/jquery.js"
]
导入jquery文件module.ts文件
import * as $ from 'jquery';
要检查我们的应用程序中包含的 jquery,请在浏览器控制台中写入 $
关于jquery - 在自定义 Angular 6+ 库中使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55969747/