You're developing an e-commerce application and want to create a shopping cart service that maintains the state of the cart across different components. What would be the best approach to ensure that all components refer to the same instance of the service?

  • Using 'ngIf' directive
  • Using separate instances for each component
  • Using the 'providedIn' property
  • Using the 'singleton' pattern
The best approach to ensure that all components refer to the same instance of a service is to use the 'singleton' pattern, which allows a single instance of the service to be shared among multiple components.
Add your answer
Loading...

Leave a comment

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