Angular-将Fontawesome导出到功能模块 [英] Angular - export fontawesome to a feature module

查看:48
本文介绍了Angular-将Fontawesome导出到功能模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在app.module中,我得到了以下有关fontawesome的行

In app.module I got the following lines regarding fontawesome

import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { faBars, faCopyright } from '@fortawesome/free-solid-svg-icons';

export class AppModule { 
  constructor(private library: FaIconLibrary) {
  library.addIcons(faBars, faCopyright);
}

我如何将它们包括在功能模块中?构造函数让我很烦

how can i include them in a feature module? the costructor part is troubling me

推荐答案

使用

Icon library is provided using root scope, so you'll always have a single icon library instance per whole application. Therefore it is safe to inject it in the constructor of the feature module and add icons there.

尽管您可以从延迟加载的模块构造函数中添加图标,但实际上这不会给您带来任何好处.您也可以在 AppModule 中添加所有图标.这是因为FA图标的打包方式以及Angular CLI构建工具链的工作方式.所有FA图标都在单个模块中定义,因此,一旦导入任何图标,所有图标(在您的应用程序中使用)都将被加载.这是因为Webpack无法将一个模块拆分为多个模块.例如.如果您同步导入至少一个图标,则无论是否已将它们导入到延迟加载的模块中,所有图标都将独立加载.

Although you can add icons from the lazy-loaded module constructor, in practice this will not gain you anything. You can as well add all icons in the AppModule. This is because of how FA icons are packaged and how Angular CLI build toolchain works. All FA icons are defined in the single module, so as soon as any of the icons is imported, all icons (used in your application) will be loaded. This is because Webpack can't split one module into multiple. E.g. if you import at least one icon synchronously, all icons will be loaded independently of whether you've imported them in the lazy-loaded module or not.

这篇关于Angular-将Fontawesome导出到功能模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆