【问题标题】:Bootstrap not getting installed in angularBootstrap 没有安装在 Angular 中
【发布时间】:2020-06-23 16:38:14
【问题描述】:

我用 Angular 创建了一个新项目。为了安装引导程序,我给出了命令 "npm install bootstrap" 。它没有安装软件包,而是提供了以下错误: 错误:

  • bootstrap@4.5.0 在 23.422 秒内更新了 1 个包并审核了 1477 个包

50 个软件包正在寻找资金 运行npm fund了解详情

发现 3 个漏洞(2 个中等,1 个高) 运行npm audit fix 来修复它们,或者运行npm audit 了解详情

根据我的理解,我输入了“npm audit”,但我无法安装引导程序。

【问题讨论】:

    标签: angular


    【解决方案1】:

    这是你需要做的:

    • 安装jquery

      npm 安装 jquery

    • 安装popper

      npm install popper

    • 编辑你的 angular.json 文件:

    1. 将以下条目添加到“样式”数组中:

      “node_modules/bootstrap/dist/css/bootstrap.min.css”

    2. 按以下顺序将以下条目添加到“脚本”数组中:

      "node_modules/jquery/dist/jquery.min.js", “node_modules/popper/client/tape/client.min.js”, “node_modules/bootstrap/dist/js/bootstrap.min.js”

    • 停止“ng serve”命令并再次运行。

    解释:

    在您的情况下,引导程序以前在您的 package.json 文件中,并且 npm 更新了它。 Bootstrap 还需要 jquery 和 popper 才能工作。

    您需要做的是在您的 angular.json 文件中导入 jquery、popper 和 bootstrap,这是编译器查找它可能需要的脚本的地方。

    【讨论】:

    • 另一个选项是不使用引导程序或 jquery。当然你可以使用bootstrap.css,但是真的不推荐使用jQuery,我建议使用ng-bootstrap:ng-bootstrap.github.io/#/homeinsted 这个
    • 这是一个有效的答案,另一种选择是通过 cdn 包含引导程序
    猜你喜欢
    • 2020-01-25
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2018-07-05
    • 2020-04-16
    • 1970-01-01
    • 2019-10-01
    相关资源
    最近更新 更多