我正在尝试使用将 Jquery 合并到我的 Angular 8 项目中var $ = require('jquery');但是,当我调用此方法时$(MyControl).tooltip({'title': data.text, html:true});我得到一个TypeError: $(...).tooltip is not a function我的 angular.json 脚本部分看起来完全像这样,所以 jquery 在其他两个之前声明"scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/@popperjs/core/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" ],是什么导致了这个错误?更新 好吧,这只是奇怪所以将这些js文件放在我的angular.json中的样式标题下它可以工作 "styles": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/popper.js/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js", "src/styles.css" ],将它们放在脚本部分下它不起作用,将它们完全从 angular.json 中删除并且它们不起作用。它只有两个地方起作用,即直接在 index.html 中作为 CDN 或在样式部分中。为什么这在样式而不是脚本下起作用有什么押韵或理由吗?
1 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
在要使用 jQuery 插件的角度组件中声明一个名为 jQuery 或 $ 的变量。
declare var $: any;
或者
declare var jQuery: any;
declare关键字用于环境声明,您希望在其中定义可能不是源自 TypeScript 文件的变量。
添加回答
举报
0/150
提交
取消
