首页 > 解决方案 > Bootstrap 5 Popover 错误 - 找不到名称“bootstrap”

问题描述

我正在尝试在我的 Angular 12 项目的 Javascript 中创建一个弹出框。我正在使用 Boostrap v5.0.1。当我尝试创建弹出框时,我似乎无法摆脱名称错误:

 var exampleEl = document.getElementById(item.name + index);
 var tooltip = new bootstrap.Popover(exampleEl, {
    container: 'body',
    animation: true
 });

打字稿告诉我"Can't find name bootstrap"

我已将 bootrap.js 添加到我的 angular.json 文件中:

"scripts": [
   "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]

根据文档,popper.js 包含在捆绑文件中。我没有使用 jQuery,也不想包含它。我还没有看到另一篇有类似问题的帖子,所以我一定只是忽略了一些小事。有任何想法吗?

标签: javascripttwitter-bootstrapbootstrap-5bootstrap-popover

解决方案


在文件顶部发布此声明有效:

declare var bootstrap: any;

推荐阅读