jquery - 在自定义 Angular 6+ 库中使用 jQuery

标签 jquery angular

编辑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
生成的文件夹结构如下所示

angular library folder structure

最佳答案

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/

相关文章:

c# - 如何从JSON格式的DataSet中提取DataTable

jquery - Grails + jQuery : formRemote onSuccess

javascript - 使用 Rxjs 的 `takeUntil` 自动取消订阅 - 无需等待发射?

Angular2 - 如何在组件内进行 UTF-8 编码

node.js - mongoose - 按 id 删除元素

javascript - 从 Razor 代码中使用 javascript/jquery

jquery - CSS/jQuery - 调整嵌套容器的宽度

javascript - 尝试将值从 JS 发送到 PHP - JQuery 的 $.ajax() 方法不起作用

angular - 如何通过 firebase 异步更新 ng2-charts 中的值

javascript - 来自 EventEmitter 的热共享 Observable