Search code examples
angularangular-signalsangular19

What capacity does the linked signal in Angular 19 have that the computed signal in Angular 18 lacks?


I've seen the official docs as well as a bunch of lyrical blogs. Despite that, I still can't understand what's the fuss is about. I do understand what linkedSignal and computed are. What I do not get is how they're different.

It's said that the limitation of the latter is that it's not writeable. Correct. But in what way is the former writable? We can't do linky.set("shazoo"), can we? It's only possible for it to react to a change in another signal and then, produce a recomputed value to its consumer. However, that's precisely what the other does.

Angular 18: using computed signal.

export class Angy18 {
  ...
  siggy = signal(1);
  compy = computed(() => siggy() * 2);
}

Angular 19: using linked signal.

export class Angy19 {
  ...
  siggy = signal(1);
  linky = linkedSignal({
    source: this.siggy;
    computation: () => siggy() * 2);
  });
}

To me, it appears that the only difference is the verbose multi-line syntax is required. I'm certain that the gain of linked signals lies elsewhere. What am I missing?


Solution

  • We can't do linky.set("shazoo"), can we?

    We can.

    To me, it appears that the only difference is the verbose multi-line syntax is required.

    By the way, the simple form is also available:

    linky = linkedSignal(() => this.siggy() * 2));