liveBook · Manning

ElementInjector

As explained in Modern Angular

An ElementInjector is an Angular injector associated with a DOM element, directive, or component instance in the rendered view hierarchy.

An ElementInjector is associated with each rendered DOM node, component instance, or directive instance. It is empty by default and receives providers declared for that component or directive. section 3.1.3

Dependency lookup follows a hierarchy. Angular checks the relevant ElementInjector and moves upward; older applications then relied on ModuleInjector, while fully standalone applications can reach route or main.ts providers instead. section 3.1.3

Repeated component instances

When an *ngFor renders five EmployeeListComponent instances, Angular creates five ElementInjectors and repeats dependency resolution for EmployeeService for each instance. Directives receive equivalent per-instance treatment. section 3.1.3

Figure 3.2 Diagram illustrating the hierarchy of injectors and dependencies
figure

Use the injector hierarchy diagram to trace how dependency resolution moves between element-level and broader provider scopes. section 3.1.3

How Modern Angular covers it

How deep it goes
Describes creation, provider registration, and hierarchical lookup, but stops short of internal injector implementation.
Examples
Uses EmployeeListComponent, EmployeeService, directives, and an *ngFor rendering five component instances.
What it assumes
Assumes familiarity with Angular dependency injection, components, directives, providers, and standalone versus NgModule applications.
What you can do after
Understand how Angular scopes and resolves dependencies for individual component and directive instances.
How it connects
Connects ElementInjector with dependency injection, providers, root injector, ModuleInjector, standalone components, routes, and directives.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.