Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 9 + FontAwesome 0.6: "Error NG8001: 'fa-icon' is not a known element"

I'm facing a problem trying to use fontawesome icons. I'd already installed FontAwesome with command line into my project:

ng add @fortawesome/angular-fontawesome@latest

I have a submodule and I want to use "fas"->"images" icon just inside it. So, I'd created my submodule:

import { PhotoListComponent } from './photo-list.component';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas } from '@fortawesome/free-solid-svg-icons';

@NgModule({
  declarations: [
    PhotoListComponent
  ],
  imports: [
    CommonModule,
    FontAwesomeModule
  ]
})
export class PhotoListModule {
  constructor() {
    library.add(fas);
  }
}

I have a component in this submodule (photo-list.component.ts and photo-list.component.html). In its HTML file I just put this line to show icon in my title:

<h1><fa-icon [icon]="['fas','images']"></fa-icon> Images</h1>

When I run my angular project and open this module, the following error occurs (and icon does note display): Error NG8001: 'fa-icon' is not a known element

Why doesn't it work?

like image 410
Carlos Diego Quirino Lima Avatar asked Apr 18 '20 15:04

Carlos Diego Quirino Lima


People also ask

How do I use Font Awesome icons with angular?

Font Awesome now has an official Angular component that’s available for all who want to easily use our icons in projects. Plan to use the SVG+JS method of Font Awesome with Angular. Have your project files handy to work on. The Font Awesome Angular component is available on npm and that's also where we maintain its official documentation.

How to add Font-Awesome to angular 9?

In this step, you need to just install font-awesome on your angular 9 and import css file to style.css file. this is only for css importing. so you can run command bellow: After successfully, installed font-awesome, we need to import css files on angular.json file. so let's add following lines on it.

Is not a known element ng8001 error?

Error NG8001: 'fa-icon' is not a known element. Here's a solution on fixing these errors. Where FontAwesomeModule is only in the imports section. Does the consumer HTML page contain components that are not there?

Can I use web fonts with CSS with AngularJS?

You've Got Options! The Font Awesome Angular component is a great option for integrating with AngularJS projects, but you can also opt to use Web Fonts with CSS with a Kit or by self-hosting.


2 Answers

I've checked the code: there were some changes in fontawesome and now the correct import has to be next:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';

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

import { faCoffee, fas } from '@fortawesome/free-solid-svg-icons';

@NgModule({
  imports:      [ BrowserModule, FormsModule, FontAwesomeModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { 
  constructor(library: FaIconLibrary) {
    library.addIconPacks(fas);
    library.addIcons(faCoffee);
  }
}

see the working example, based on your code: https://stackblitz.com/edit/angular-5qu1fy

like image 183
Danil Sabirov Avatar answered Sep 21 '22 03:09

Danil Sabirov


I know this is an old question but if someone is using Angular Material I would like to add some information. As per their documentation https://github.com/FortAwesome/angular-fontawesome. Just import the fontawesome in your material module , and then use it in any components and bind property in html, like;

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
    
@NgModule({
  imports: [FontAwesomeModule]
})
export class MaterialModule {}

//any component
import { faGoogle } from '@fortawesome/free-brands-svg-icons';

googleIcon = faGoogle;

//html
<fa-icon [icon]="googleIcon"></fa-icon>
like image 40
Dildar Khan Avatar answered Sep 23 '22 03:09

Dildar Khan