50

I am working with Angular(6) application, and I am trying to use FA icons, and drop-down with no luck. I am successfully using FA(4) icons, like:

<i class="fa fa-align-justify"></i>

But <i class="fas fa-align-justify"></i> is not working. I am using following command to install FA:

npm install font-awesome --save

This is from package.json in node_modules folder:

image

I can see font-awesome.css, but it says Font Awesome 4.7.0 as shown below:

image

In angular.json file, I referenced FA: "node_modules/font-awesome/css/font-awesome.min.css",

I read a lot of posts like How to use font Awesome 5 installed via NPM

What do I need to do else?

itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
E.Meir
  • 2,146
  • 7
  • 34
  • 52

5 Answers5

97

For version 5, you need following package @fortawesome/fontawesome. See installation using package managers.

Using npm:

npm install --save @fortawesome/fontawesome-free

Then reference either the all.css or all.js in the <head>.

<link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-free/css/all.css">

Note: Make sure the path is right, depends on where you installed the package from.

OR you can import the module in your js code.

import '@fortawesome/fontawesome-free/js/all.js';

OR if you are using Sass, you can import the module in app.scss.

@import '~@fortawesome/fontawesome-free/scss/fontawesome';
@import '~@fortawesome/fontawesome-free/scss/<type>';

Note: Replace <type> with solid, brands or regular whatever type of icons you need.


Font Awesome has an official Angular component.

npm install --save @fortawesome/fontawesome-svg-core
npm install --save @fortawesome/free-<type>-svg-icons
npm install --save @fortawesome/angular-fontawesome

Note: Replace <type> with solid, brands or regular whatever type of icons you need.


You can also install Vue and React components.

npm install --save @fortawesome/vue-fontawesome
npm install --save @fortawesome/react-fontawesome
itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
  • 1
    i just ran the command `npm install @fortawesome/fontawesome-free`, still under `node_modules` > `font-awesome.css` showing the version `4.7.` i tried to delete the folder before i ran `npm install @fortawesome/fontawesome-free`, and the icon ` ` is not showing – E.Meir Sep 22 '18 at 14:54
  • if i use the CDN suggested [here](https://fontawesome.com/how-to-use/on-the-web/setup/getting-started?using=web-fonts-with-css) the icon is showing, but i really dont want to use it like that and prefer to use package manager. – E.Meir Sep 22 '18 at 15:00
  • It's showing 5.3.1 in my case.. What folders are being shown to you? When I downloaded, I got this stucture: "node_modules\@fortawesome\fontawesome-free\css". And in css folder, when I open fontawesome.css file, it shows 5.3.1 in it. – itsmysterybox Sep 22 '18 at 15:08
  • 1
    Thanks, found the problem, and i have no clue why it is working like this, after runing the command `npm install @fortawesome/fontawesome-free` in `node_modules` these 2 folders are getting copied 1- `font-awesome` it's version 4.7.0,and also 2- `@fortawesome` version 5.3.1. why do you think that it happens? maybe i have an old dependency – E.Meir Sep 22 '18 at 15:19
  • 2
    just checked, and i have an old dependency for the version 4.7.0, so i referenced it by mistake :/ it was showed under `devDependencies` in `pckages.json` – E.Meir Sep 22 '18 at 15:20
  • 1
    I guess it would have made too much sense to PLAINLY state this fact on their website, +1! – Scott Weaver Jun 10 '19 at 23:43
16

For Font Awesome 4.7.0:

It should work by simply doing:

npm install font-awesome --save

And adding:

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

...to your styles.css or styles.scss.


For Font Awesome 5 use the official Font Awesome 5 angular component

npm add @fortawesome/fontawesome-svg-core
npm add @fortawesome/free-solid-svg-icons
npm add @fortawesome/angular-fontawesome

In your template:

<div style="text-align:center">
  <fa-icon [icon]="faAlignJustify"></fa-icon>
</div>

In your typescript:

import { faAlignJustify } from '@fortawesome/free-solid-svg-icons';

export class MyComponent {
  faAlignJustify = faAlignJustify;
}

In the module of your component:

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

@NgModule({
  declarations: [
    MyComponent
  ],
  imports: [
    BrowserModule,
    FontAwesomeModule
  ]
})
export class MyModule { }
Spikolynn
  • 4,067
  • 2
  • 37
  • 44
Wingnod
  • 595
  • 3
  • 9
12

If you are using npm install --save @fortawesome/fontawesome-free change the package.json to refer

import "@fortawesome/fontawesome-free/css/all.css"; 
CharithU
  • 121
  • 1
  • 3
5

Alternatively, you can install fontawesome as a module in your js code.

Steps:

  1. npm install @fortawesome/fontawesome-free --save
  2. in your javascript code import the all.js file as instructed at the very bottom of the instructions here.
import '@fortawesome/fontawesome-free/js/all.js';

- or -

require('@fortawesome/fontawesome-free/js/all.js');
BruceJo
  • 591
  • 6
  • 17
2

A stumbling block for me was the final part of their installation docs. It says to reference the all.css file in your head tag.

I did it incorrectly.

The right way to link to this is the following:

<link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-pro/css/all.css">

Hope this helps!


This should get it working for you. Also, I would recommend reinstalling the latest version of the npm package using the FontAwesome guide

itsmysterybox
  • 2,748
  • 3
  • 21
  • 26