【问题标题】:Bootstrap version 3.4 not working in Angular 9Bootstrap 3.4 版在 Angular 9 中不起作用
【发布时间】:2020-04-03 08:05:46
【问题描述】:

我已经使用 Angular cli 安装了 bootstrap 3.4 版。下面是我使用的命令 npm install --save bootstrap@3 然后我添加了

"styles": [
          "./node_modules/bootstrap/dist/css/bootstrap.min.css",
          "src/styles.css"
        ],
        "scripts": [
          "./node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]

在 angular.json 文件中。 但我无法访问引导程序默认样式类。每当我运行应用程序时,浏览器控制台中都不会显示引导文件。

我在这里找不到问题。您的帮助将不胜感激。 添加我的 node_modules 文件夹的屏幕截图

【问题讨论】:

标签: angular twitter-bootstrap-3


【解决方案1】:

添加

@import "~bootstrap/dist/css/bootstrap.css";

到 src/styles 文件。

【讨论】:

    【解决方案2】:

    删除相对路径使用,如下所示。由于 src 直接使用就像使用 node_modules 而不是 ./node_modules

    "styles": [
    
                  "node_modules/bootstrap/dist/css/bootstrap.min.css",
                  "src/styles.css"
                ],
    

    一个好的资源链接是

    https://medium.com/@oyewusioyekunle/how-to-add-bootstrap-to-your-angular-project-angular-8-6379fd6a0f46

    【讨论】:

      【解决方案3】:

      您的路径不应以 ./ 开头。

      请尝试以下方法:

      "styles": [
        "node_modules/bootstrap/dist/css/bootstrap.min.css",
        "src/styles.css"
      ],
      "scripts": [
        "node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]
      

      现在这使它们相对于项目根目录。

      工作演示:https://stackblitz.com/edit/angular-etn2fd

      【讨论】:

      • 这个我也试过了,也没用。
      • 您是否导航到 mode_modules 文件夹以确保文件存在?
      • 是的,我也检查过了。
      • 您是否尝试在更新这些路径后重新构建应用程序?
      • 是的,我做到了。
      猜你喜欢
      • 2021-11-25
      • 2020-05-29
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多