How can you share a service instance between multiple lazy-loaded modules in Angular?
- Manually create a service instance in each lazy-loaded module
- Provide the service in a shared module and import that module into each lazy-loaded module
- Use Angular's built-in lazy-loading service provider
- Use the 'shared' attribute in the service decorator
To share a service instance between multiple lazy-loaded modules, you should provide the service in a shared module and then import that shared module into each of the lazy-loaded modules that need access to the service. This ensures that there's only one instance of the service across those modules.
Loading...
Related Quiz
- What method can be used to manually trigger change detection in Angular?
- When creating a shared service that should retain state and be available for all components, the service should be provided in _____.
- The process of synchronizing the UI with the underlying form model in Reactive Forms is called ______.
- How can you manually request a change detection cycle for a specific component?
- The NG_VALUE_ACCESSOR token is used to provide the ________ for a custom form control.