Skip to content

Reset a linkedSignal (or any WritableSignal) #70030

Description

@tijsmoree

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Would it be useful to add a reset function to linkedSignal (or even any WritableSignal), so you can reset the signal to its latest computation?

I often use linkedSignal for "form models" I create my signal form from. Example:

public readonly person = input<Person>();

protected readonly raw = linkedSignal<Person | undefined, Person>({
  source: this.person,
  computation: (person, previous) => {
    const base = previous?.value ?? {
      firstName: '',
      lastName: '',
    };

    return { ...base, ...person };
  },
});

protected readonly form = form(this.raw);

Adding a reset function would allow me to reset the form, which can be useful.

Proposed solution

Add a reset function to linkedSignal.

Alternatives considered

It's definitely a nice-to-have; there are plenty of ways to achieve the same without the reset function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issuesforms: signals

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions