简体   繁体   English

将全局使用的库模块导入angular个工程模块

[英]Import globally used library module into angular project modules

I think I did something wrong here.我想我在这里做错了什么。

I want to use angular-fontawesome module .我想使用angular-fontawesome模块 Following the instructions to import it into AppModule successfully.按照说明成功将其导入AppModule

export class AppModule {
constructor(library: FaIconLibrary) {
    // Add an icon to the library for convenient access in other components
    library.addIcons(
        faUsers,
        faUserCircle,
        faDesktop,
        faTachometerAlt,
        faWrench,
        faFolder,
        faChartArea,
        faTable,
        faSearch,
        faBell,
        faFileAlt,
        faExclamationTriangle,
        faDonate,
        faEnvelope,
        faUser,
        faCogs,
        faList,
        faSignOutAlt,
        faAngleUp,
        faLaughWink,
        faServer,
        faWarehouse,
        faPlusCircle
    )
}     

But when I want to use it in my own in-project module, say admin.module.ts .但是当我想在我自己的项目模块中使用它时,说admin.module.ts I have to import all that again?我必须再次导入所有这些吗? The same code have to be placed into admin.module.ts again?必须再次将相同的代码放入admin.module.ts吗?

It seems to me.在我看来。 AppModule is the root module. AppModule是根模块。 I get that if I have other modules that I want to use icons then I might have to do this.我知道如果我有其他模块想使用图标,那么我可能必须这样做。 But, really?但是,真的吗? Even the AppModule is not enough?AppModule都不够用?

The FaIconLibrary is an application-level singleton , so you only need to add icons to the library once. FaIconLibrary是一个应用级的 singleton ,所以你只需要添加一次图标到库中。 However you should add FontAwesomeModule to imports of your AdminModule to make <fa-icon> component accessible to the components declared in the AdminModule (it's a standard Angular thing ).但是,您应该将FontAwesomeModule添加到AdminModuleimports中,以使AdminModule中声明的组件可以访问<fa-icon>组件(这是标准的Angular 事物)。

You may also find this answer interesting to read.您可能还会发现这个答案很有趣。

According to documentation根据文档

Icons can be registered once in app.module with FaIconLibrary.addIcons() or FaIconLibrary.addIconPacks().图标可以在 app.module 中使用 FaIconLibrary.addIcons() 或 FaIconLibrary.addIconPacks() 注册一次。 Icons added to the library will be available to any other components whose parent module also imports FontAwesomeModule.添加到库中的图标将可用于其父模块也导入 FontAwesomeModule 的任何其他组件。

So re check next steps所以重新检查后续步骤

1   Import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome'
2   Add FontAwesomeModule to imports
3   Inject FaIconLibrary into constructor of the module.
4   Import an icon like { faCoffee } from '@fortawesome/free-solid-svg-icons'
5   Add icon to the library with library.addIcons(faCoffee)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM