我已经通过https://www.npmjs.com/package/angular-font-awesome的npm install --save font-awesome angular-font-awesome
安装了真棒字体。
在angular.json中将其链接
"styles": [
"src/styles.css",
"node_modules/font-awesome/css/font-awesome.min.css"
]
在index.html中,我已链接库
<link rel="stylesheet" type="text/css" href="../node_modules/font-awesome/css/font-awesome.min.css">
我的图标HTML代码如下:
<i class="fa fa-facebook-f"></i>
显示静止正方形而不是图标。
有人可以帮忙吗?
答案 0 :(得分:2)
要安装《真棒字体》,请使用:
$ npm install @fortawesome/fontawesome-svg-core
$ npm install @fortawesome/free-solid-svg-icons
然后我们需要将其导入app.module.ts
:
imports: [
BrowserModule,
FontAwesomeModule
],
src / app / app.component.html:
<div style="text-align:center">
<fa-icon [icon]="faCoffee"></fa-icon>
</div>
src / app / app.component.ts
import { Component } from '@angular/core';
import { faCoffee } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
faCoffee = faCoffee;
}
更新:
可以通过添加faFacebook
图标来使用Facebook字体。让我举个例子。
要安装软件包free-regular-svg-icons
:
npm i --save @fortawesome/free-regular-svg-icons
要安装软件包free-regular-svg-icons
:
npm i --save @fortawesome/free-brands-svg-icon
App.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { faSquare, faCheckSquare } from '@fortawesome/free-solid-svg-icons';
import { faSquare as farSquare, faCheckSquare as farCheckSquare } from '@fortawesome/free-regular-svg-icons';
import { faStackOverflow, faGithub, faMedium, faFacebook } from '@fortawesome/free-brands-svg-icons';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
@NgModule({
imports: [ BrowserModule, FormsModule, FontAwesomeModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
constructor(private library: FaIconLibrary) {
library.addIcons(faSquare, faCheckSquare, farSquare
, farCheckSquare, faStackOverflow, faGithub, faMedium, faFacebook);
}
}
app.component.html:
<div style="text-align:center">
<h2>Using Brand Icons</h2>
<fa-icon [icon]="['fab', 'stack-overflow']"></fa-icon>
<br>
<fa-icon [icon]="['fab', 'github']"></fa-icon>
<br>
<fa-icon [icon]="['fab', 'medium']"></fa-icon>
<br>
<fa-icon [icon]="['fab', 'facebook']"></fa-icon>
<br>
</div>
答案 1 :(得分:1)
您使用的库不再受支持。店主建议使用以下一种: https://github.com/FortAwesome/angular-fontawesome
答案 2 :(得分:0)
我认为您没有在主模块中导入FontAwesome模块:
import { AngularFontAwesomeModule } from 'angular-font-awesome';
@NgModule({
//...
imports: [
//...
AngularFontAwesomeModule
],
//...
})
export class AppModule { }
编辑
由于您在angular.json中添加了CSS,因此无需在index.html中添加<link>
标签。