Visitar URL original
signal-forms: FormValueControl throws error when using both min and updating value · Issue #63625 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20250916014305/https://github.com/angular/angular/issues/63625
Skip to content

signal-forms: FormValueControl throws error when using both min and updating value #63625

@Harpush

Description

@Harpush

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

forms

Is this a regression?

No

Description

When trying to implement FormValueControl and using min and max to disable buttons an error is thrown when updating value.
The UI control I tried creating is:
Image

When clicking on + and the value is at max the error is thrown.

@Component({
  selector: 'app-num-picker',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    @let max = this.max();
    <button (click)="addOne()" [disabled]="max !== undefined && value() >= max">+</button>
    <span>{{ value() }}</span>
    @let min = this.min();
    <button (click)="subOne()" [disabled]="min !== undefined && value() <= min">-</button>
  `,
})
export class NumPicker implements FormValueControl<number> {
  readonly value = model<number>(0);
  readonly min = input<number | undefined>(undefined);
  readonly max = input<number | undefined>(undefined);

  protected addOne() {
    this.value.update((value) => value + 1);
  }

  protected subOne() {
    this.value.update((value) => value - 1);
  }
}

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-gjgm6kt6?file=src%2Fmain.ts

Please provide the exception or error you saw

Uncaught RuntimeError: NG0600: Writing to signals is not allowed while Angular renders the template (eg. interpolations)
    at debug_node.mjs:19352:15
    at throwInvalidWriteToSignalError (signal.mjs:481:5)
    at signalSetFn (signal.mjs:525:9)
    at getter.set2 [as set] (signal.mjs:510:31)
    at FieldNodeState.markAsTouched (signals.mjs:2086:22)
    at _FieldNode.markAsTouched (signals.mjs:2020:20)
    at HTMLElement.listener (signals.mjs:3312:24)
    at NoneEncapsulationDomRenderer.setProperty (dom_renderer.mjs:703:12)
    at setDomProperty (debug_node.mjs:8100:18)
    at ɵɵdomProperty (debug_node.mjs:22941:9)

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

Angular CLI: 21.0.0-next.2
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
    

Angular: 21.0.0-next.2
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2100.0-next.2
@angular-devkit/core         21.0.0-next.2
@angular-devkit/schematics   21.0.0-next.2
@schematics/angular          21.0.0-next.2
rxjs                         7.8.2
typescript                   5.9.2

Anything else?

I might be doing it wrong which causes the error...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions