How to install Font Awesome 5 in Angular 6?

0

Since I do not use yarn search for npm ( link ).

In src / app / app.module.ts

  

Import {FontAwesomeModule} from '@ fortawesome / angular-fontawesome'

I add it to imports

  

FontAwesomeModule

And this causes me the following error by console:

Uncaught Error: Unexpected value 'undefined' imported by the module 'AppModule'     at syntaxError (compiler.js: 1016)     at compiler.js: 10584     at Array.forEach ()     at CompileMetadataResolver.push ../ node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js: 10553)     at JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (compiler.js: 23850)     at JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js: 23831)     at JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js: 23791)     at CompilerImpl.push ../ node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync (platform-browser-dynamic.js: 143)     at PlatformRef.push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule (core.js: 4352)     at Object ../ src / main.ts (main.ts: 11)

Update 1:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { routing, appRoutingProviders } from './app.routing';
import { DataTablesModule } from 'angular-datatables';
import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule } from '@angular/forms';

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

import { AppComponent } from './app.component';
import { HomeComponent } from './components/home.component';
import { ConversorPipe } from './pipes/conversorMayusMinus.pipe';
import { ErrorComponent } from './components/error.component';

import { CategoriaComponent } from './components/categoria.component';
import { ColorComponent } from './components/color.component';

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    ConversorPipe,
    ErrorComponent,
    CategoriaComponent,
    ColorComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing,
    ReactiveFormsModule,
    HttpClientModule,
    DataTablesModule,
    FontAwesomeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Update 2:

Change the next line of code

  

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

for this:

  

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

This generates the following error:

  

./ node_modules/@fortawesome/angular-fontawesome/fesm5/angular-fontawesome.js   Module not found: Error: Can not resolve '@ fortwesome / fontawesome-svg-core' in 'C: \ wamp64 \ www \ webapp \ node_modules \ @fortawesome \ angular-fontawesome \ fesm5'

Update 3: Add:

  

import {library} from '@ fortawesome / fontawesome-svg-core';

It generates the following error:

Update 4:

Following the suggestion of @ LPZadkiel .

    
asked by Pablo Contreras 03.10.2018 в 17:13
source

1 answer

1

In view and considering that you are using npm and not yarn since you have no other option but to use the icons in the html style. You must do it in the following way

run

npm install FortAwesome/Font-Awesome

then in the file angular.json add the following

        "styles": [
           "node_modules/@fortawesome/fontawesome-free/js/all.css"
        ]

or this (either of the two options works)

"scripts": [
          "node_modules/@fortawesome/fontawesome-free/js/all.js"
        ]

and then you use them by adding the icons in the html:

<i class="fa fa-camera-retro fa-lg"></i>

is just adding the class so you can still do it from the files typescript

NOTE: With this solution you should not make a import { FontAwesomeModule } from ... just add the file all.css or all.js (only one not both) and you start using it with the class in the html elements <i>

    
answered by 03.10.2018 / 18:14
source