codejump

DI Internals

Preview — 3 of 10 questions

In Angular's Ivy (R3) DI system, how does the injector resolve a token?

AIt performs a linear scan of a flat providers array
BIt uses a bloom filter for fast negative lookups, then resolves via a slot-indexed record array on the injector's _records map
CIt traverses the component tree using breadth-first search
DIt uses a WeakMap keyed by the token's class reference

What is the fundamental architectural difference between NodeInjector and EnvironmentInjector?

ANodeInjector is for components; EnvironmentInjector is for directives only
BNodeInjector supports signals; EnvironmentInjector supports only class-based services
CNodeInjector can only hold one provider; EnvironmentInjector supports unlimited providers
DNodeInjector is embedded in the view's tNode data structure (no separate object per node); EnvironmentInjector is a standalone object with its own records map

How does providedIn: 'root' achieve tree-shaking for services?

AThe service's ɵprov static property contains the factory; the module's ɵinj references the factory only when the service is injected somewhere, allowing static analysis to prune unused entries
BWebpack/esbuild analyzes all @Injectable decorators and removes unused ones
CAngular compiles a manifest of all services and the CLI removes unused ones during ng build
DTree-shaking works because @Injectable classes extend a base class that is conditionally included

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.