【问题标题】:Link to bootstrap not working in Angular 2链接到引导程序在 Angular 2 中不起作用
【发布时间】:2017-05-23 04:38:07
【问题描述】:

在 index.html 中,如下所示,我试图链接到位于 node_modules 文件夹中的 bootstrap.css,但出现错误。

应用的文件夹结构:

电子商务应用程序/节点模块

电子商务应用程序/src/app/index.html

在 index.html 中,以下所有对 bootstrap.css 的引用都会产生错误:

<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">

<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.css">

<link rel="stylesheet" href="../../node_modules/bootstrap/dist/css/bootstrap.css">

这是错误: 获取http://localhost:3000/node_modules/bootstrap/dist/css/bootstrap.css 没有找到

【问题讨论】:

  • 检查它们是否不在assets 文件夹中。如:assets/css/bootstrap.min.css
  • bootstrap.css 肯定在 node_module 文件夹中,如上面的链接所示。我在资产 ecommerce.css 中有一个文件,它的链接可以正常工作:
  • 你在使用 Angular-CLI 吗?
  • 我在 Angular-CLI 中遇到了同样的问题。

标签: html twitter-bootstrap angular


【解决方案1】:

如果您使用的是 Angular-CLI,请将其添加到您的 angular-cli.json

"apps": [
    {
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.css"
      ],

【讨论】:

  • localhost:4200/node_modules/bootstrap/dist/css/bootstrap.css 加载资源失败:服务器响应状态为 404(未找到)
  • 调整路径。尝试删除../,或将其更改为./
  • 我之前尝试过../。 ./ 也不起作用。
  • 你的angular-cli.json在哪里?它在子文件夹中吗?
  • @koque 这将起作用并将 bootstrap.css 添加到样式包中,以便您可以从 index.html 中删除不需要的链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 2021-11-29
  • 1970-01-01
  • 2018-05-08
  • 1970-01-01
相关资源
最近更新 更多