【问题标题】:How to properly display Bootstrap in Angular?如何在 Angular 中正确显示 Bootstrap?
【发布时间】:2022-01-03 11:49:50
【问题描述】:

我现在正在学习 Angular。在本教程中,我应该使用 Bootstrap:

<ul class="nav nav-pills">
    <li class="active"><a href="">Map View</a></li>
    <li><a href=""></a>List View</li>
</ul>
<div>
    <div>Map View Content</div>
</div> 

为了输出这个:

相反,我得到了这个:

我可以看到 Bootstrap 不起作用。所以我检查了是否安装了 Bootstrap 和 jQuery,它们是(都在 node_modules 文件夹中):

我检查了我是否正确导入。我尝试了两种方法。首先,我在styles.css 上导入Bootstrap 是这样的:

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

它没有工作。所以我尝试了另一种方法,在 angular.json 文件中添加 Bootstrap 和 jQuery,如下所示:

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

我的问题是:是否有任何我可能遗漏的额外步骤?我已经查看了很多资料,似乎我的一切都是正确的。有没有更好的选择来让 Bootstrap 正确显示?我真的很困惑,如果能得到任何帮助,我将不胜感激。谢谢!

【问题讨论】:

    标签: angular angular-ui-bootstrap


    【解决方案1】:

    尝试删除开头的“./”:

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

    【讨论】:

    • 我试过了,但不幸的是还是不行
    • 怎么样?你能分享一下你的文件夹结构的截图吗?
    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2023-04-06
    • 2020-01-14
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    相关资源
    最近更新 更多