javascript - 如何在 Angular 2 应用程序中包含 jquery 库
问题描述
如何在 Angular 2 应用程序中包含第三方 jQuery 库?
如何在 Angular 2 应用程序中包含http://keith-wood.name/calendarspicker.html jQuery 库?
解决方案
1-除了通过 npm 安装之外,尝试在你的 angular-cli.json 文件中包含这一行,在 apps->scripts 键中,如下例所示:
{
"apps": {
"scripts": [
"../node_modules/jquery/dist/jquery.min.js"
]
}
}
2-将此插件添加到 webpack.config.js 中的 webpack 插件(在 module.exports 中):
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
3- 然后将它导入到你需要使用它的组件中,例如:
import * as $ from 'jquery';
推荐阅读
- c# - 如何读取文本文件并将数据添加到具有绑定源的数据网格视图
- python - 如何从 mongodb 中删除重复的行?
- ruby - 如何为 Ruby 类的 Singleton 实例定义类变量?
- python - 如何为从批处理文件运行的 python 脚本传递可变命令行参数?
- windows - Qt Creator 因 link.exe 路径错误而无法打开 CMake 项目
- angular - 将传单 ImageOverlay 添加到图层控件
- c# - 使用 ZipFile 创建 .zip 文件时收到“该进程无法访问该文件,因为它正被另一个进程使用”
- javascript - 如何使用 ajax 使用数据库中的数据填充带有选择选项的输入?
- html - Amp-carousel 停止自动播放功能非常随机 - AMPHTML Ads
- angular6 - 材料仪表板选项卡中的分页不起作用