Import all icons from Fontawesome
As in docs here, you can do
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
export class AppModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(fas, far);
}
}
import { fas } from '@fortawesome/fontawesome-free-solid';
and then
fontawesome.library.add(fas)
same for other styles
import { fab } from '@fortawesome/fontawesome-free-brands';
import { far } from '@fortawesome/fontawesome-free-regular';
...
fontawesome.library.add( fab, far );
Here is how I did it, I first import the Font awesome packages into the app module:
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { fab } from '@fortawesome/free-brands-svg-icons';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
Importing the FontAwesomeModule also into the imports section.
Add the following in to your constructor of app module:
constructor(){
library.add(fab, far, fas);
}
Now you can reference the Font Awesome icons from inside any component like in this markup example:
<div class="crop"
(click)="onClick()"
[style.width.px]="starWidth"
[title]="rating">
<div style="width: 75px">
<span><fa-icon [icon]="['far', 'star']"></fa-icon></span>
<span><fa-icon [icon]="['far', 'star']"></fa-icon></span>
<span><fa-icon [icon]="['far', 'star']"></fa-icon></span>
<span><fa-icon [icon]="['far', 'star']"></fa-icon></span>
<span><fa-icon [icon]="['far', 'star']"></fa-icon></span>
</div>
</div>
Note that if you do not use the solid icons from the 'fas' library, you must specify the type of Font Awesome icon library, such as 'far' for the regular icons.
I ended up with using the following npm packages: "@fortawesome/angular-fontawesome": "^0.3.0", "@fortawesome/fontawesome-svg-core": "^1.2.21", "@fortawesome/free-brands-svg-icons": "^5.10.1", "@fortawesome/free-regular-svg-icons": "^5.10.1", "@fortawesome/free-solid-svg-icons": "^5.10.1",
Note: I did a downgrade to version 0.3.0 of the angular-fontawesome package.
Tested out in Angular 8.