Angular · Junior · Question 29 of 75
What is a service in Angular?
@Injectable({ providedIn: "root" })
export class CartService {
items = signal<Item[]>([]);
}- ✓Correct answer: A class with shared logic or data that Angular creates and injects where it is needed
- 2A component without a template
- 3A Web Worker that runs in the background
Explanation
Services hold business logic, API calls and shared state, keeping components thin. providedIn: 'root' registers one app-wide instance that is tree-shaken away if no one uses it.