Recall & Review
beginner
What is the purpose of injecting a service into an Angular component?
Injecting a service allows the component to use shared logic or data provided by the service, promoting code reuse and separation of concerns.
Click to reveal answer
intermediate
How do you inject a service into a standalone Angular component?
Use the
inject() function inside the component's code to get the service instance, instead of constructor injection.Click to reveal answer
beginner
What decorator is used to make a class a service that can be injected?The <code>@Injectable()</code> decorator marks a class as a service that Angular can inject into components or other services.Click to reveal answer
intermediate
What is the difference between injecting a service via constructor and using the inject() function?
Constructor injection is the traditional way and works in class-based components, while
inject() is a new function useful in standalone components and functional contexts.Click to reveal answer
beginner
Why is dependency injection important in Angular applications?
It helps manage dependencies cleanly, makes testing easier, and allows components to stay focused on UI logic without managing service creation.
Click to reveal answer
Which Angular decorator is used to define a service that can be injected?
✗ Incorrect
The @Injectable decorator marks a class as a service that Angular can inject.
In Angular 17+, what function can be used inside a standalone component to inject a service?
✗ Incorrect
The inject() function is the new recommended way to inject services in standalone components.
What is the main benefit of injecting services into components?
✗ Incorrect
Injecting services helps reuse logic and keeps components focused on UI.
Which of the following is NOT a way to inject a service in Angular?
✗ Incorrect
Using new keyword manually bypasses Angular's dependency injection system and is not recommended.
Where should you provide a service to make it available application-wide?
✗ Incorrect
Providing a service in the root injector makes it available throughout the app.
Explain how to inject a service into a standalone Angular component and why this method is useful.
Think about how Angular 17 changed dependency injection for standalone components.
You got /4 concepts.
Describe the role of the @Injectable decorator in Angular services and how it relates to dependency injection.
Consider what makes a class a service Angular can inject.
You got /4 concepts.