Angular · Middle · Question 62 of 75

How do you expose a signal from a service without letting components change it?

private readonly _items = signal<Item[]>([]);
readonly items = this._items.asReadonly();

Explanation

Components read items(), and changes go through the service's methods. This keeps updates in one place.

Further reading

Problem with a question

Angular · Middle · question 62

Test yourself

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

Take this quiz