I am currently developing an Ionic 3 application. In this context, I needed an accordion component like the one of NgBootstrap but the Ionic framework does not provide such a component. So I decided to implement one myself, what is a good opportunity to me to continue to learn Angular 5.
To clarify the context of my question, you need to know that my component is defined through this file tree:
components/
my-accordion/
my-accordion.component.html
my-accordion.component.css
my-accordion.component.ts
my-accordion.service.ts
Actually, I need a specific service to allow communication between all instances of my components. Because when I open one of the item of my accordion, I want the other to be closed automatically to have only one opened item at a time. I don't know if it is the right way to do it but it seems to work well with the RxJS library.
Anyway, as you can see, the definition of my accordion depends on a Component AND a Service. Without the service, my accordion cannot works well. The thing is I would like to put it in a module that I could share with other application to be able to reuse my accordion.
The first idea I had was to put it in the SharedModule, but the ngModules FAQs explicitely says that:
The SharedModule should not have providers for reasons explained previously. Nor should any of its imported or re-exported NgModules have providers.
After reading that, my second thought was to put my accordion in the CoreModule, but again the doc explicitely said that:
Consider making CoreModule a pure services module with no declarations.
Hence my question: Where to put a component AND it service (for sibling communication) if I want to be able to reuse it in other Ionic/Angular application ?