Skip to content

Reactive forms: transformedValue control shows an empty value after reset() followed by setting the previous value #72068

Open

Description

@itsokto

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

A FormValueControl that uses transformedValue shows an empty input after a reactive form is reset and then set back to the value it had before the reset, in the same tick.

import { ChangeDetectionStrategy, Component, model } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { FormValueControl, transformedValue } from '@angular/forms/signals';
import { bootstrapApplication } from '@angular/platform-browser';

@Component({
  selector: 'app-text-input',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `<input [value]="rawValue()" (input)="rawValue.set($any($event.target).value)" />`,
})
export class TextInput implements FormValueControl<string | null> {
  readonly value = model<string | null>(null);
  protected readonly rawValue = transformedValue(this.value, {
    parse: (raw: string) => ({ value: raw || null }),
    format: (value: string | null) => value ?? '',
  });
}

@Component({
  selector: 'app-root',
  imports: [ReactiveFormsModule, TextInput],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <form [formGroup]="form">
      <app-text-input formControlName="name" />
      <input formControlName="name" />
    </form>
    <button (click)="reload()">reset + patchValue (same value)</button>
    <p>Control value: "{{ form.value.name }}"</p>
  `,
})
export class App {
  protected readonly form = new FormGroup({ name: new FormControl<string | null>('Ada') });

  protected reload(): void {
    this.form.reset();
    this.form.patchValue({ name: 'Ada' });
  }
}

bootstrapApplication(App);

Click the button. The native input and the control value still show "Ada", but the custom input is empty. If change detection runs between reset() and patchValue(), everything stays in sync.

Cause

The reset propagation added in 849dba6 updates the raw value without updating the model or the cache of the last value written to the control:

  1. On FormResetEvent, NgControl calls the reset callback with control.value, which is null here (ng_control.ts).
  2. transformedValue writes format(null) into its raw-value linkedSignal with originalSet, bypassing the model on purpose (transformed_value.ts). The control's value model is still 'Ada', because NgControl only writes it during change detection.
  3. patchValue({name: 'Ada'}) sets the FormControl back to 'Ada'.
  4. During change detection, ngControlUpdate skips the write because customControlBindings.value is still 'Ada' (ng_control.ts). The model never changes, so the linkedSignal never recomputes and keeps the empty raw value.

The same commit handles this for CVA controls under [formField]: the reset binding in control_cva.ts writes the value and updates bindings['controlValue'], so later updates are compared against what the control really holds. The FVC path under NgControl has no equivalent.

Proposed fix

Mirror the CVA reset in NgControl. On FormResetEvent, before calling the reset callback, NgControl should write the reset value to the custom control's value model and update customControlBindings.value to match. Any pending custom value (for updateOn: 'blur' or 'submit') should be discarded at the same time, as ngControlUpdate already does when it overwrites the control.

The model has to be written during the reset, not on the next change detection. If the write is deferred, transformedValue still formats the reset value while the model holds the old one, and when the previous value is written back the model doesn't change, so the raw value is never recomputed.

Please provide a link to a minimal reproduction of the bug

The example in the description is a complete src/main.ts: paste it into a new Angular 22 project (for example ng new --minimal) and run ng serve.

Please provide the exception or error you saw

No errors

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 22.2.7
Angular           : 22.2.6
Node.js           : 22.23.3
Package Manager   : yarn 1.22.22
Operating System  : win32 x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.2.7            │ 22.2.7            │
│ @angular/cli              │ 22.2.7            │ 22.2.7            │
│ @angular/common           │ 22.2.6            │ 22.2.6            │
│ @angular/compiler         │ 22.2.6            │ 22.2.6            │
│ @angular/compiler-cli     │ 22.2.6            │ 22.2.6            │
│ @angular/core             │ 22.2.6            │ 22.2.6            │
│ @angular/forms            │ 22.2.6            │ 22.2.6            │
│ @angular/platform-browser │ 22.2.6            │ 22.2.6            │
│ rxjs                      │ 7.8.2             │ 7.8.2             │
│ typescript                │ 6.0.3             │ ~6.0.3            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

#72065 looks related but is a different problem: there the control writes its own model under [formField], and the remembered value in control_custom.ts is not updated. Here the control's model is never written; only the raw value of transformedValue is.

Activity

  1. added this to the needsTriage milestone on Nov 16, 2026
  2. added this to the needsTriage milestone on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions