Carlos Pisarello
Carlos Pisarello

Reputation: 1284

Font-awesome icons not loading on Angular4 project

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:

Upvotes: 9

Views: 28970

Answers (6)

Om Prakash N
Om Prakash N

Reputation: 149

I had everything correct and it was working. I made changes to the design and the icons were displayed as box.

The issue was font-family. I had mentioned the font-family in css to all elements: *{ font-family: "inter" } .

Changing it to html, body{ font-family: "inter" } fixed it and font awesome started working fine.

Upvotes: 3

Mounir bkr
Mounir bkr

Reputation: 1665

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" />

Upvotes: 0

Salad.Guyo
Salad.Guyo

Reputation: 3415

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"
  ],

Upvotes: 4

Deekshith Anand
Deekshith Anand

Reputation: 2692

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!!!!

Upvotes: 1

Hojjat Bakhtiyari
Hojjat Bakhtiyari

Reputation: 187

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

Upvotes: 2

Andy Roberts
Andy Roberts

Reputation: 945

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/

Upvotes: 27

Related Questions