9

I'm working on an angular 4 project using font-awesome, i followed this guide to install the library with npm: How to add font-awesome to Angular 2 + CLI project

i've configured the project to compile the scss stylesheets with the ng-serve command, my styles paths of the angular-cli.json looks like this:

"styles": [
        "../node_modules/bootstrap/scss/bootstrap.scss",
        "../node_modules/bootstrap/scss/main.scss",
        "../node_modules/font-awesome/scss/font-awesome.scss"

      ],

i want to make a button with an address card icon on it, i'm also working with Bootstrap 4, so it looks like this:

<button class="btn btn-sm btn-primary"><span class="fas fa-address-card"></span></button>

but when it loads, it looks like this:

Corné
  • 1,304
  • 3
  • 13
  • 32
Carlos Pisarello
  • 1,254
  • 5
  • 20
  • 39

5 Answers5

27

You should be using the class fa instead of fas. The fa class sets the font-face. (hat tip to @mike-hill)

View source on http://fontawesome.io/icon/address-card/

Andy Roberts
  • 905
  • 8
  • 6
4

Font-awesome version 5+

fa prefix has been depricated from version 5. In order to use fas prefix install version 5+ and include in your styles.

install:

yourapp$npm install @fortawesome/fontawesome-free --save

package.json

"styles": [
   "node_modules/@fortawesome/fontawesome-free/css/all.css",
   "src/styles.scss"
  ],
Community
  • 1
  • 1
7guyo
  • 3,047
  • 1
  • 30
  • 31
1

After adding dependencies to Angular.json or Angular-cli.json. 1) stop running App 2) start it It will recognize new resources

  • It took me almost 2 days to figure out my issue.. Thank you for mentioning to restart app after adding new resources.. – Naila Akbar Aug 30 '19 at 19:57
1

First make sure you have properly setup the project requirements to use font-awesome icons by including them in styles[] in angular.jason or simply importing them by like this:

@import "~font-awesome/css/font-awesome.css";

in the component css file. Then it is necessary to have "fa" class in addition to what the font-icons markup gives you. Alternatively you can do like this:

<div class="fa">
<i class="whateverTheIconClassYouWant"></i>
</div>

Inside the div with class="fa" you can directly copy paste the code that is provided in font awsome website.

Hope this helps! Happy coding!!!!

Deekshith Anand
  • 2,175
  • 1
  • 21
  • 24
0

after installing font awesome, you can add this to index.html

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
Mounir bkr
  • 1,069
  • 6
  • 6