gpt4 book ai didi

angular - Angular CLI : 8. 2.2 中未显示 Font Awesome 图标,而是显示方 block

转载 作者:行者123 更新时间:2023-12-03 23:10:50 26 4
gpt4 key购买 nike

我已经通过 npm install --save font-awesome angular-font-awesome 安装了 Font Awesome来自 https://www.npmjs.com/package/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>

仍然显示方块而不是图标。

任何人都可以帮忙吗?

最佳答案

要安装 «font-awesome» 使用:

$ npm install @fortawesome/angular-fontawesome@<version>
$ 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 fontawesome图标。让我举一个例子。
安装包 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>
It can be seen at stackblitz.com.

关于angular - Angular CLI : 8. 2.2 中未显示 Font Awesome 图标,而是显示方 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57670433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com