1

I'm encountering an issue with module dependencies in my Angular application. I have a CoreModule where I've declared certain components, services, or pipes. This CoreModule is then imported into the AppModule. However, components declared in other feature modules, which import a SharedModule that also imports CoreModule, cannot access declarations (components, services, pipes) from the CoreModule. Components can only use these declarations if they are declared directly in the AppModule.

Why can't components in feature modules, which import SharedModule, access declarations from CoreModule, and how can I ensure that all modules, including SharedModule, have access to declarations from CoreModule?

1 Answer 1

1

Only what you export will be visible to the modules that import it.

So firstly make sure you export CoreModule in the shared module, you need to add it to the exports array of shared module.

Then make sure you export all the feature you want to share outside the module in the exports array of the core module.

Sign up to request clarification or add additional context in comments.

9 Comments

yes i know but the problem is caused by a pipe , and the problem is in a components that are not a modules , so i only have two solutions , i return the pipe declaration in shared module and i imported once again in the module that does not import shared module because shared module has a lot of components i don't need in that module or declare this pipe in app.module.ts so all components can acces to it
@ahmeed import the shared module or core module in the imports array of the standalone component and solve your issue
@ahmeed tree shaking will ensure you use only what you need , if the module is loaded once it's not loaded again, else convert the pipe to standalone
sorry but didn't undrestand you so well , i export core module in shared module and in app module , the problem that pipe existed in core module is not recognised by certain components that are not in shared and non modules , just regular components and they are not standalone ,but they're declared in shared module , i can't declare them in app module that will create a problems in some modules existing in shared
when i import and export core module in shared module the problem solved but it's not logical since i imported and exported in app.moduke.ts
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.