الانتقال إلى المحتوى
FrontendAngular· 8 دقائق للقراءة

Signal Inputs Are Read-Only: When to Reach for model() and linkedSignal()

An input belongs to the parent. Decide who owns the edit, then pick model() or linkedSignal().

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Angular 22
محتويات المقال

A team migrates a quantity stepper from @Input() quantity = 1 to quantity = input(1). The old increment() method did this.quantity++, and its new version, this.quantity.set(...), breaks the build: property set doesn't exist on type InputSignal<number>. Someone suggests a quick fix, count = signal(this.quantity()). It compiles, and the + button works. Then QA files two bugs: the cart passes 3 and the stepper shows 1, and clicking + never changes the cart total.

The common misconception

The belief: input() returns a signal, signals have set(), so a component can update its own input when the user edits it, the same way it updates any other state.

It's an easy conclusion to reach. You read an input exactly like a signal(), by calling it, and you use it in computed() and effect() the same way. Decorator inputs built the habit: an @Input() was a plain field, so this.quantity++ compiled and the number on screen changed. But that write never reached the parent, and the next time the parent's bound value changed, Angular overwrote it without a word. Decorator inputs always followed the same rule as signal inputs. Signal inputs just put it in the type.

What actually happens

An input is the parent's value, delivered

When a parent renders <app-quantity-stepper [quantity]="qty()" />, Angular evaluates the binding, writes the result into the child's input, and does it again each time the bound value changes. The InputSignal the child receives is a read-only window on that delivery: it always holds the latest value the parent bound, and it has no set() or update(). If the child could write it, the value would have two writers and no rule for who wins. The parent would keep showing its own number, and its next update would silently erase the child's. One value with one owner is the rule, and the type enforces it.

So "how do I set my input?" is the wrong question. The useful one is: who owns the edit?

  • The parent owns it and needs every change: use model().
  • The child keeps a temporary copy that starts over when the parent sends a new value: use linkedSignal().
  • Nobody edits it, you only need a different shape: use computed() or an input transform.

model(): an input that writes back

A is declared like an input, but it's a writable signal. Angular also creates an output for it, named after the input with Change appended, and emits it every time the component calls set() or update(). When the parent binds with the two-way syntax, [(quantity)]="qty", Angular feeds the parent's value in and writes every emitted value back into the parent's signal or property. The parent still owns the number; the child is allowed to change it through the binding.

TypeScript quantity-stepper.ts
import { Component, input } from '@angular/core';@Component({  selector: 'app-quantity-stepper',  template: `    <button (click)="increment()">+</button>    <span>{{ quantity() }}</span>  `,})export class QuantityStepper {  readonly quantity = input(1);  increment(): void {    // TS2339: Property 'set' does not exist on type 'InputSignal<number>'    this.quantity.set(this.quantity() + 1);  }}

With qty = signal(3) in the cart and <app-quantity-stepper [(quantity)]="qty" /> in its template, the stepper starts at 3, each click updates the cart's qty, and the total that reads qty() follows. Notice that the two-way binding passes the signal itself, qty, not its value. Angular's docs recommend model inputs when a component exists to modify a value based on user interaction, most commonly custom form controls like a date picker or a combobox.

linkedSignal(): a local draft that follows the input

Some edits shouldn't reach the parent until the user confirms them. A rename field receives the saved name, lets the user type, and reports the result only on Save. The draft needs its own writable state, and it must start over when the parent selects a different file. signal(this.name()) gets that wrong twice: it copies one value at construction, before the parent's binding is applied (an input.required() even throws NG0950 there), and it never looks at the input again. linkedSignal() gets both parts right:

TypeScript rename-field.ts
import { Component, input, linkedSignal, output } from '@angular/core';@Component({  selector: 'app-rename-field',  template: `    <input #box [value]="draft()" (input)="draft.set(box.value)" />    <button (click)="renamed.emit(draft())">Save</button>  `,})export class RenameField {  readonly name = input.required<string>();  readonly renamed = output<string>();  // Writable, and reset to the new name whenever the parent sends one  readonly draft = linkedSignal(() => this.name());}

draft is writable like any signal, so each keystroke calls draft.set(). Its computation is lazy and tracked like a computed(), so it first reads name() when the template renders, after the input is set. When the parent passes a new name, the next read of draft returns that name and the old draft is gone. Nothing reaches the parent until renamed.emit().

Transforms and computed(): when nobody writes

Often the "edit" is only a conversion. Trimming a label or accepting the string "5" for a number belongs in an input transform, like input(0, { transform: numberAttribute }), which runs each time Angular sets the input. A value derived for display, like quantity() * price(), belongs in computed(). Neither needs a writable signal. One limit to know: model inputs don't support transforms.

What the component needsUseWho owns the valueWhen the parent sends a new value
Display or derive the parent's valueinput() + computed()The parentDerived values update
Let the user change the parent's valuemodel() + [(x)]The parentThe child shows it, and child writes flow back
A draft the user edits before savinglinkedSignal()The child, until the input changesThe draft resets to it
A one-time copy, signal(this.x())Nothing: avoid itThe childIgnored: the copy stays frozen

How to apply it in your project

  1. Find every write to an inputWith signal inputs, the compiler finds them for you. With @Input() fields, search each component for assignments to its own inputs, like this.quantity = or this.quantity++.
  2. Ask who owns the editIf the parent should see each change, switch the input to model() and bind it with [(x)] in the parent.
  3. Turn local edits into a linkedSignal()For drafts, selections and other state that should reset when the input changes, use linkedSignal() and keep reporting the final value through an output().
  4. Delete one-time copiesReplace every signal(this.someInput()) initializer with linkedSignal() if the child writes it, or computed() if it doesn't.

Key takeaways

  • An input() is the parent's value: Angular writes it from the binding, and the component only reads it.
  • model() is a writable input with an implicit Change output; with [(x)], each write lands in the parent's state.
  • linkedSignal() gives the child a writable copy that resets whenever the input changes.
  • signal(this.input()) freezes one early value, so it's almost always a bug.

📚 المصادر

  1. Accepting data with input properties — Angular
  2. model — Angular API
  3. Two-way binding — Angular
  4. Dependent state with linkedSignal — Angular
  5. Migration to signal inputs — Angular

التعليقات (0)