Reputation: 2964
I added
"@fortawesome/fontawesome-free": "5.15.1"
to dependencies
in my package.json
and then I added to my html
<span class="fas fa-sign-in-alt"></span>
but nothing shows up.
What do I need to do? It's completely unclear.
I'm in a project created by VisualStudio and it has Twitter Bootstrap in the package.json
and that appears to be working without bootstrap being mentioned anywhere else, so why doesn't it work for FontAwesome?
This doesn't work.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: [
'../../node_modules/@fortawesome/fontawesome-free/css/all.min.css'
]
})
export class AppComponent {
title = 'app';
}
Adding to styles.css
:
@import "../node_modules/@fortawesome/fontawesome-free/css/fontawesome.min.css";
also doesn't work. This is crap.
What was so bad about adding a <link>
in the <head>
? This is awful.
Upvotes: 1
Views: 7224
Reputation: 2797
In your angular.json file you'll have a property that is meant to describe files or globs to include in your webpack build.
{
"projects": {
"architect": {
"build": {
"styles": [] // add the path here.
}
}
}
}
So, for your case of font-awesome, it would look something like the following:
"styles": [
"src/styles.scss",
"node_modules/@fortawesome/fontawesome-free/css/all.css"
]
To get that file, download the corresponding fortawesome-package as described on their website :
npm install --save @fortawesome/fontawesome-free
Once you've modified your angular.json
you will have to restart your angular cli for the changes to take effect.
index.html
's head section.The reason for this is that the index.html you will distribute is being generated by webpack once you run ng build
so you have to take this extra step in telling the webpack toolchain to include your style in the generated index.html's head.
For more information on Angular workspace configuraiton you can check the reference guide here: https://angular.io/guide/workspace-config
Upvotes: 1
Reputation: 15083
For use with Angular 9+
You can also consider using the angular-fontawesome
library
Steps
Using npm
$ npm install @fortawesome/fontawesome-svg-core
$ npm install @fortawesome/free-solid-svg-icons
FontAwesomeModule
to imports in src/app/app.module.ts:import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@NgModule({
imports: [
BrowserModule,
FontAwesomeModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/core';
import { faCoffee } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
faCoffee = faCoffee;
}
<fa-icon [icon]="faCoffee"></fa-icon>
Upvotes: 1