【问题标题】:Bootstrap 5 Popover Error - Cannot find name 'bootstrap'Bootstrap 5 Popover 错误 - 找不到名称“bootstrap”
【发布时间】:2021-07-01 20:39:00
【问题描述】:

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

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

Typescript 告诉我 "Can't find name bootstrap"

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

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

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

【问题讨论】:

    标签: javascript twitter-bootstrap bootstrap-5 bootstrap-popover


    【解决方案1】:

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

    declare var bootstrap: any;
    

    【讨论】:

    • 我在 Angular 组件中尝试使用引导菜单,并且遇到了同样的错误。在导入下添加此代码修复它。
    猜你喜欢
    • 2019-10-23
    • 1970-01-01
    • 2017-02-18
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    相关资源
    最近更新 更多