Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

font awesome with Angular 2

Tags:

angular

fonts

I started an NG2 app and wanna add font awesome. I npm installed it with : npm install --save font-awesome angular2-font-awesome. I added to project in systemjs.config.js:

map: {
  // our app is within the app folder
  app: 'app',

  // angular bundles
  '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
  '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
  '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
  '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
  '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
  '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
  '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
  '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

  // other libraries
  'rxjs':                      'npm:rxjs',
  'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
  'angular2-fontawesome': 'node_modules/angular2-fontawesome'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
  app: {
    defaultExtension: 'js'
  },
  rxjs: {
    defaultExtension: 'js'
  },
  'angular2-fontawesome': { defaultExtension: 'js' }
}

and I added in app.module.ts:

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

import { AppComponent }  from './app.component';
import { CorporateComponent }  from './corporate/corporate.component';
import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome'

@NgModule({
  imports:      [ BrowserModule , Angular2FontawesomeModule],
  declarations: [ AppComponent, CorporateComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

Now I try to use it in my component: I add in the html template:

<i class="fa fa-industry" aria-hidden="true"></i>

But somehow I don't see it... I followed the manual of npm: https://www.npmjs.com/package/angular2-fontawesome

Is there anything else that I might have forgotten ?

Thanks for any answer!

like image 410
moshi Avatar asked Feb 08 '17 07:02

moshi


Video Answer


1 Answers

if you wanna using FontAwesome css style in your app, just put css link to your index.html, you don't need angular2-font-awesome

index.html

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

if you using angular2-font-awesome

<i fa [name]="industry"></i>
<fa [name]="industry"></fa>

i think use cdn is better.

like image 123
Tiep Phan Avatar answered Nov 11 '22 00:11

Tiep Phan