Let's say I have a component called CarDetailsComponent which makes use of a CarApiService, both of which are in CarModule. Now I want to move that component out to a SharedModule. As multiple modules also require that same component. I cannot share the whole CarModule as it already imports the other modules (e.g:, CustomerModule, ShopModule) into it.
Moving CarDetailsComponent to SharedModule is not a problem, but how do I now handle the dependent service (CarApiService) since it is also used by the component as well as other components in the CarModule.
I tried to use providers (useClass and the lot) to replace the service with another service of the module it is being used in. However, all I end up doing is copy-pasting the same functions into the services of other modules.
I did think about moving the CarApiService into the SharedModule as well, but it really belongs in CarModule (as most of the components here use it, and only CarDetailsComponent makes use of the service).
What is a better approach here?