codejump

Hierarchical Injectors

Preview — 3 of 10 questions

When should you use InjectionToken instead of a class as an injection token?

AWhen you need to inject multiple instances of the same class
BWhen you want the service to be scoped to a single component
CWhen the value to inject is a primitive, interface, or object literal — since TypeScript interfaces are erased at runtime and can't serve as tokens
DWhen the service has no constructor dependencies

What does multi: true do in a provider configuration?

AIt creates a new instance for every injection
BIt makes the token available in child injectors automatically
CIt allows multiple providers for the same token — the injected value is an array of all provided values
DIt enables the service to be provided in multiple NgModules simultaneously

What is APP_INITIALIZER used for?

ATo run code before the first component renders, optionally delaying bootstrap until async operations complete
BTo initialize component inputs before ngOnInit
CTo set up the Angular testing environment
DTo lazily load a module before routing starts

Sign up free to play

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