Using NgIconsModule in SharedModules #79
-
Hi, I can import Icons using the NgIconsModule without any problem but I can't export them. How can I use them in this way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, sure, so as you discovered you cannot export them from an NgModule, the reason for that is that NgModules can only export components. Our icons are not components but instead are strings that are registered in Angular's dependency injection system. With the way the DI system works this makes icons available to any child components (or lazy loaded modules) without any need to export. To make icons available to your entire application you can either register them in the AppModule: @NgModule({
imports: [NgIconsModule.withIcons(MaterialIcons)]
})
export AppModule {} Or have a @NgModule({
imports: [NgIconsModule.withIcons(MaterialIcons)]
})
export CoreModule {}
@NgModule({
imports: [CoreModule]
})
export AppModule {} If you want however you can still export the NgIcon component in your shared module, this will allow any components with access to shared module access to use @NgModule({
imports: [NgIconsModule],
exports: [NgIconsModule],
})
export SharedModule {} If anything is unclear let me know and I will try and clarify further. |
Beta Was this translation helpful? Give feedback.
Hi, sure, so as you discovered you cannot export them from an NgModule, the reason for that is that NgModules can only export components. Our icons are not components but instead are strings that are registered in Angular's dependency injection system. With the way the DI system works this makes icons available to any child components (or lazy loaded modules) without any need to export.
To make icons available to your entire application you can either register them in the AppModule:
Or have a
CoreModule
that your AppModule imports. This module typically contains anything that registers things with the…