Register fontawesome icons for use with material MatIcon
29.04.2021Add fontawesome to our angular project
npm i font-awesome --save
"styles": [ "node_modules/font-awesome/scss/font-awesome.scss", ]
<link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" as="style>
Register fontawesome to use with MatIcon
import { MatIconModule, MatIconRegistry } from '@angular/material'; imports: [ MatIconModule ], providers: [ MatIconRegistry ]
export class MaterialModule { constructor(public matIconRegistry: MatIconRegistry) { matIconRegistry.registerFontClassAlias('fontawesome', 'fa'); } }
Use fontawesome icons in HTML
<mat-icon fontSet="fa" fontIcon="fa-shopping-bag"></mat-icon>
.mat-icon.fa { font-size: 20px; }