0

What’s the difference between @Injectable({ providedIn: 'root' }) and using providedIn: 'any' in Angular services?

author
subina kallyani
hard
0
335

Answer
  • root: Creates a singleton service shared across the app.
  • any: Creates a new instance in every lazy-loaded module that uses the service.

This is critical when services need isolated states per module, like separate caches for different feature areas.


Click to Reveal Answer

Tap anywhere to see the solution

Revealed

Comments0
    What’s the difference between @Injectable({ providedIn: 'root' }) and using providedIn: 'any' in Angular services? - dependency injection | EBAT