Module Export and Import
In Angular, modules encapsulate a cohesive set of components, directives, pipes, and services. Modules can be imported into other modules to make their contents available for use. When sharing components across modules, we use the concepts of module export and import:
- Exporting Components: Components that need to be shared across modules are exported from their defining module using the
exports
property of the@NgModule
decorator. - Importing Modules: Modules containing the exported components are imported into other modules where the components are needed using the
imports
property of the@NgModule
decorator.
Use component from another module -Angular
Angular’s modular architecture is one of its core strengths, allowing it to break down large applications into smaller, manageable pieces. A key aspect of modularity in Angular is the ability to share components across different modules. You can promote code reuse and maintainability by exporting and importing components between modules. In this article, we’ll see how to use Angular’s modularity by sharing components across modules.
Table of Content
- Module Export and Import
- Benefits of Sharing Components Across Modules
- Exporting the Component from its Module
- Moving the Component to the Shared Module
Contact Us