NG.IV · Angular 22 practice question
A developer needs to create a reusable data management class in an Angular application. They have two options: using the CLI or manual definition. Which approach allows them to clearly signal to the Angular framework that this class should be managed as a dependency?
import {Service} from '@angular/core';
@Service()
export class DataManager { /* ... */ }
Check answer and explanation
Correct answer: Manually adding the @Service() decorator to the class definition.
Explanation
Manually adding the @Service() decorator to the class definition tells Angular that the class is an injectable dependency, as shown in the example provided.
Common trap
Running the CLI command alone doesn't guarantee the dependency registration needed for injection; while it creates the file, the decorator is what explicitly marks it for DI. The @Injectable() decorator is for general dependency injection, but the source specifically mentions @Service() for this context.
Source: Angular docs: Creating and using services — Creating a service
Checked against the cited text on 2026-11-25.