how to use Glyphicons in bootstrap 4 and angular2?

2019-05-26 05:46发布

问题:

I am doing an app with angular-cli and bootstrap4, but when I do some references to Glyphicons, the icons don´t appear. For example, when I add the following code:

<button type="button" class="btn btn-default btn-lg">
  <span class="glyphicon glyphicon-star" aria-hidden="true"></span> Star
</button>

I did the bootstrap installation in my angular project with:

$ npm install --save bootstrap@4.0.0-alpha.6

I should make any extra step to have the Glyphicons in bootstrap? Do I should install another npm package specific for Glyphicons?

回答1:

There are no Glyphicons now in Bootstrap 4 so you'd use another icon package such as FontAwesome or installed the Glyphicons separately.



回答2:

As already mentioned, Bootstrap 4 doesn't include glyphicon in self release.

I am using FontAwesome and that dependencies in my cases:

  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.9",
    "bootstrap": "4.0.0",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "jquery": "^3.2.1",
    "popper.js": "^1.12.9",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.5",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }

In HTML templates just place a code like that:

<i class="fa fa-refresh" aria-hidden="true"></i>


回答3:

I recently purchased the entire Glyphicons set and added it to my Angular application. Here is my process:

  1. Create a Glyphicons folder in the assets folder here src/assets/glyphicons
  2. Add glyphicons.css to the folder above.
  3. Add this in styles.css
    "styles": ["styles.css", "../src/assets/glyphicons/glyphicons.css"],
  4. Create a fonts folder at src/assets/fonts
  5. Inside the fonts folder place the following files
    -glyphicons-regular.eot
    -glyphicons-regular.svg
    -glyphicons-regular.ttf
    -glyphicons-regular.woff
    -glyphicons-regular.woff2