Angular · Senior · Question 8 of 75
What is wrong with this effect?
total = signal(0);
constructor() {
effect(() => this.total.set(this.price() * this.qty()));
}- ✓Correct answer: Derived state should be
computed(); syncing signals with effects adds extra cycles and risks loops - 2Effects can't read more than one signal
- 3
setcan't be called with a number
Explanation
total = computed(() => this.price() * this.qty()) is synchronous, lazy and always consistent. Use linkedSignal if it must also be writable; reserve effects for side effects outside the signal graph (DOM, storage, logging).