angular - 在 Angular 6 版本中通过 angular-cli.json 导入 font-awesome?
问题描述
我被讲师指定在 angular-cli.json 文件中导入 font-awesome,但我使用的是 angular 6,所以我在 angular.json 文件中初始化了 font awesome 节点模块,但它不工作并且在 ng serve 中出错。
解决方案
安装包npm install --save font-awesome angular-font-awesome
导入模块:
//...
import { AngularFontAwesomeModule } from 'angular-font-awesome';
@NgModule({
//...
imports: [
//...
AngularFontAwesomeModule
],
//...
})
export class AppModule { }
如果您使用的是 Angular CLI,请将 font-awesome CSS 添加styles
到angular-cli.json
"styles": [
"styles.css",
"../node_modules/font-awesome/css/font-awesome.css"
],
注意:如果使用 SCSS 预处理器,只需将 css 更改为 scss
如果您不使用 CLI,请将样式表导入您的 index.html 文件
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
如果您使用错误的命令安装 font-awesome:
- 删除安装的依赖项
package.json
node_modules
手动 删除文件夹。- 跑
npm cache clean --force
- 跑
npm install
- 并执行我上面提到的步骤。
推荐阅读
- android - 房间没有返回 livedata 的结果
- c++ - 在同一个字符串文字中包含 \n 字符是否比在额外的一组“<<”中更有效?
- heroku - 如何在不损害声誉的情况下通过 SendGrid 插件测试发送电子邮件?
- python - TypeError: 'str' 对象不能被解释为整数,尽管使用了 int() 函数
- c# - EF Core - 复杂查询
- swiftui - 关闭 FullScreenCover 后 NavigationLink 不会触发
- python - 在 qtablewidget 的每一行添加 qcheckbox
- python - 将 2 个日期之间的天数拆分为 30 或 31 个批次,并在每种情况下返回开始日期
- ide - Atom:如何禁用“望远镜”项目部分(“您的项目当前为空”)?
- python - ImportError: [E048] Can't import language en from spacy.lang: No module named 'spacy.matcher' 我该如何解决这个问题?