Service
noun
say it: “SER-vis” /ˈsɜːrvɪs/
A shared Angular class for logic or data that many components use.
What is Service?
A service is a class that holds logic or data shared by many components, such as calling an API or keeping the shopping cart. Components ask for services instead of creating them.
@Injectable({ providedIn: 'root' })
export class CartService {
items: Product[] = [];
add(product: Product) { this.items.push(product); }
}
In a sentence
- “The Cart service holds the cart, and every component reads it.”
Level: Apprentice · More Angular terms at this level
Updated