Bootstrap 4 Glyphicons没有显示在Angular 4项目上

时间:2017-12-06 22:17:42

标签: angular twitter-bootstrap bootstrap-4 glyphicons

我正在使用带有Sass的Bootstrap 4处理Angular 4项目,我想使用字形,但是当我使用以下代码时:

<button class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-thumbs-up"></span>Like</button>

例如,制作&#34;喜欢&#34;按钮,图标不显示。

我将项目配置为使用ng-serve命令编译SCSS样式表,我的angular-cli.json如下所示:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "front-end-informatorio"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/scss/bootstrap.scss",
        "../node_modules/bootstrap/scss/main.scss"

      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

我尝试在index.html

中将其关联起来
<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css"/>

它使图标有效,但也改变了我项目的整体风格。

如何在不重叠样式的情况下实现它?

1 个答案:

答案 0 :(得分:27)

Bootstrap 4掉落Glyphicons支持。 (见:https://getbootstrap.com/docs/4.0/migration/#components

这意味着您需要使用其他图标字体,例如Font Awesome

Font Awesome的快速入门

  1. get started page
  2. 抓取脚本
  3. 将其粘贴到<head>
  4. 开始使用!FontAwesome.com
  5. 上搜索图标
  6. 探索docs以释放Font Awesome的全部潜力!
  7. 示例:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Bootstrap + Font Awesome</title>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
        <script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
      </head>
      <body>
        <div class="container">
          <!-- display 4 class makes the font size increase -->
          <h1 class="display-4"><i class="fab fa-stack-overflow"></i></h1>
          <p>That was easy! <i class="far fa-thumbs-up"></i></p>
          <button type="button" class="btn btn-primary">Works also with buttons! <i class="fas fa-link"></i></button>
        </div>
      </body>
    </html>

    Angular Font Awesome组件

    Font Awesome团队正在开发一个Angular Font Awesome组件。它现在正处于预发布状态,但您可以找到它here