This is my SharedModule
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { IconModule } from "@my-app/components/icon/icon.module";
import { RequiredActionDirective } from "@my-app/directives/required-action.directive";
@NgModule({
imports: [
CommonModule,
IconModule
],
declarations: [
RequiredActionDirective
],
exports: [
CommonModule,
IconModule,
FormsModule,
ReactiveFormsModule,
RequiredActionDirective
]
})
export class SharedModule { }
Please note that I added to Imports
only CommonModule
and IconModule
. I did it because I'm using those modules in my RequiredActionDirective
. But Exports
has more Modules because will be used by other modules that will import SharedModule
.
Question: am I thinking correctly that I don't need to add Modules to Imports
unless I want to use them directly in SharedModule
? Or in future there might be some problems of which I am currently not aware because now everything is working properly?
Yes, you are correct. You could even technically get rid of
CommonModule
from imports inSharedModule
, but there is a high chance that some of the stuff may need it now or later, so I would not recommend it.Also in terms of
CommonModule
: Notice thatCommonModule
is automatically added to imports when generating new module using CLI. It means that it is available right away, however it can be safely deleted since we already export it inSharedModule
. It can be useful when optimizing redundant imports, but it's really up to you.