When creating a shared service that should retain state and be available for all components, the service should be provided in _____.

  • app.module.ts (root module)
  • providers array of each component
  • providers array of each component and the root module
  • services.ts (custom service file)
When creating a shared service in Angular that should retain state and be available for all components, the service should be provided in the app.module.ts (root module). Providing the service in the root module's providers array ensures that a single instance of the service is created and shared across all components of the application. This makes it a suitable choice for managing global state or shared functionality.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *