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); }- ✓Correct answer: The signal reference doesn't change, so Angular isn't notified; use
update(list => [...list, x]) - 2Signals can't contain arrays
- 3
pushthrows an error inside signals
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.