0
0
Angularframework~5 mins

How dependency injection works in Angular - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is Dependency Injection (DI) in Angular?
Dependency Injection in Angular is a design pattern where Angular automatically provides components or services with the dependencies they need, instead of creating them manually.
Click to reveal answer
intermediate
How does Angular know which dependency to inject?
Angular uses tokens, usually class types, to look up and provide the correct dependency from its injector tree.
Click to reveal answer
intermediate
What is an Angular injector?
An injector is a container that holds and manages the creation and lifetime of dependencies. Angular creates a tree of injectors to provide dependencies at different levels.
Click to reveal answer
beginner
What is the role of the @Injectable() decorator in Angular DI?
The @Injectable() decorator marks a class as available to be injected as a dependency and allows Angular to inject other dependencies into it if needed.
Click to reveal answer
beginner
How can you provide a service at the root level in Angular?
You can provide a service at the root level by adding providedIn: 'root' in the @Injectable() decorator, making it a singleton available throughout the app.
Click to reveal answer
What does Angular use to decide which dependency to inject?
ARandom selection
BTokens like class types
CManual user input
DFile names
What decorator marks a class as injectable in Angular?
A@Component
B@Directive
C@Injectable
D@NgModule
Where is a service provided if you use providedIn: 'root'?
AIn the root injector, available app-wide
BOnly in the component
CIn the module only
DNowhere, it disables the service
What is the Angular injector responsible for?
AManaging dependencies and their lifetimes
BHandling HTTP requests
CRendering UI
DStyling components
How does Angular provide dependencies to a component?
ABy using global variables
BBy manually creating them inside the component
CBy importing them in the template
DBy injecting them through the constructor
Explain how Angular's dependency injection system finds and provides a service to a component.
Think about how Angular uses the constructor and injector to supply dependencies.
You got /4 concepts.
    Describe the purpose of the @Injectable() decorator in Angular dependency injection.
    Consider what makes a class ready to be used as a service.
    You got /4 concepts.