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.
Loading...
Related Quiz
- Which testing framework is primarily used alongside Angular for unit testing?
- Which operator is best suited for handling multiple click events in rapid succession with RxJS in Angular?
- How can you share a service instance between multiple lazy-loaded modules in Angular?
- For configuring proxies during development to bypass CORS issues, you'd modify the ______ file in an Angular CLI project.
- When generating a new component using Angular CLI, how can you ensure that it does not produce a separate CSS file but instead uses inline styles?