Member-only story
Why use linkedSignal instead of computed in Angular Signals?
Question
Trying to understand the differences between linkedSignal and computed in Angular’s Signals system, and why linkedSignal would be preferred in certain situations.
For example, if I want to manage a selectedOption that depends on shippingOptions, why not use computed like this:
const shippingOptions = signal(['Ground', 'Air', 'Sea']);
const selectedOption = computed(() => shippingOptions()[0]);
Why linkedSignal is a better choice in scenarios like this?
I haven’t tried implementing this yet — I’m trying to understand the conceptual differences between linkedSignal and computed. Based on what I understand, computed should work fine for dependent state. I’m wondering what makes linkedSignal a better option in Angular’s Signals system.
Answer
A linkedSignal is a writable signal that is already derived from another reactive expression.
Indeed :
const selectedOption = linkedSignal(() => shippingOptions()[0]);
is the same as
const selectedOption = computed(() => shippingOptions()[0]);