简体   繁体   中英

Is There a way to share data from one component to another component which are in different modules by using @Input decorator

I have two different components in separate modules i am importing one module into another module and referring imported modules component html selector in the module's component, sample text is printing in <router-outlet> when i tried sending data using @Input decorator to the other component it is throwing an error saying Error: Template parse errors: Can't bind to 'themeingColors' since it isn't a known property of 'app-color- palette-container'. I got to know by the error that components should be under same module to get benefit by @Input

But my question is there a way we can achieve passing data by using @Input decorator even if the components are in different modules?

There are multiple ways of sharing data between components: Input/Output decors, shared service and passing the components as reference. If they are in separate modules(and if they are lazy loaded), you should use the shared service aproach. Where you instantiate a service on app initialization and use it as a global ''state'' container for such things as themes. But dont overuse it for everything cuz it get really messy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM