Angular · Junior · Question 39 of 75

Why is it wrong to mutate an array inside a signal like this?

items = signal<string[]>([]);
add(x: string) { this.items().push(x); }

Explanation

Signals compare values with Object.is by default. Mutating the same array keeps the reference, so dependents are not notified. Create a new array or object instead.

Further reading

Problem with a question

Angular · Junior · question 39

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