Getting into hierarchical injectors in Angular modules
When you build an Angular app, you keep meeting the same question. Where does a service come from when a component asks for it. It feels a bit like asking for a tool in a big workshop. You reach out, and Angular hands you one. But which one, and from where.
That is where hierarchical injectors show up. They are basically a stack of places Angular can search for a dependency. It starts close to the component, then moves upward through parents, then through the module level, and finally the root injector if needed. This is why two parts of the app can use “the same service” but still not share the same instance.
I like thinking about it with real tasks. Like building a feature module for an admin area. You may want an AdminSettingsService that is shared inside admin pages only, not across the whole app. Hierarchical injectors let you do that without hacks. You decide where to provide the service, and Angular follows that choice when it resolves dependencies.
A small ending
If dependency injection ever felt like magic, this topic makes it less magic and more logic. Once you see the hierarchy, bugs like “why is my state resetting” start making way more sense.