@Service
noun
say it: “SER-vis” /ˈsɜːrvɪs/
The Angular 22 decorator that marks a class as a service shared across the whole app.
What does @Service() do in Angular?
@Service — The decorator, new in Angular 22, that marks a class as a service and registers it for the whole app: one shared instance for every component that asks for it with inject(). Older code writes the same thing as @Injectable({ providedIn: 'root' }).
import { Service } from '@angular/core';
@Service()
export class PriceCalculator {
withTax(price: number): number {
return Math.round(price * 1.08 * 100) / 100;
}
}
In a sentence
- “PriceCalculator is marked @Service(), so every component that injects it gets the same one.”
Level: Apprentice · More Angular terms at this level
Updated