Angular · Junior · Question 29 of 75

What is a service in Angular?

@Injectable({ providedIn: "root" })
export class CartService {
  items = signal<Item[]>([]);
}

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.

Further reading

Problem with a question

Angular · Junior · question 29

Test yourself

Take the Angular · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz