CodeZettaInterview Hub

Angular · Dependency Injection · Junior · Comparison

What is providedIn: 'root' vs providing in a component?

Short Interview Answer

Root creates an app-wide singleton; component providers create an instance per component injector.

Detailed Explanation

Use root for shared services. Provide on a component/route to scope state to a feature subtree. Mis-scoping causes shared mutable state bugs.

Did you know this answer?