Question · Angular course · Module 5: Services and DI

providedIn: 'root' vs providers

How does providedIn: 'root' differ from adding a service to a component's providers?

Answer options

  • providedIn: 'root' gives a singleton and tree-shaking, while providers creates an instance per component
  • Both always create the same, single instance
  • providers gives a singleton, while providedIn: 'root' gives an instance per component
  • There is no difference between them

You can check the correct answer by solving this task in the CodeWorlds game.