Issue
Hi guys I am fairly new to the angular space and am trying to use a component that I created in AppModule in two other modules to reduce redundant code. I tried exporting the component from AppModule and import in the other modules but that did not seem to work.
Doing that gave me the errors:
error NG6002: Appears in the NgModule.imports of AdminModule, but could not be resolved to an NgModule class.
error NG6004: Present in the NgModule.exports of AppModule but neither declared nor imported.
I am unable to solve the error. Can any of you give any suggestions as to how I can achieve my goal?
Solution
My suggestion is the following:
- If you have a folder with "shared" components, create a shared module for all of them. Include your components array in the
declarations
andexports
of the shared module. Include this shared module in every component you wish to use it. - If you only want to use this component as "shared", just create a module for it, add it to
exports
and again include this module wherever you want to use the component.
To answer your issue, it's coming from the fact that you're not importing the module
that's exporting your required component.
Answered By - justchecking
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.