Signal inputs, model inputs, and outputs
The input(), model(), and output() functions that replace @Input()/@Output() with signal-based component APIs.
Signal inputs, model inputs, and outputs
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- `input()` creates a signal, not a plain property — reading it is `this.user()`, not `this.user`, and Angular updates that signal whenever the parent's binding changes.
- `model()` is a two-way-capable input: the parent can bind it with `[(value)]`, exactly like `[(ngModel)]`, and the child can both read and write it.
- `output()` is a lighter-weight replacement for `@Output() x = new EventEmitter()` — same emit-and-listen behavior, without needing to construct an `EventEmitter` yourself.
The decorator-based API predates signals
@Input() and @Output() work fine, and nothing in the previous lesson stops
working. But they were designed before Angular had signals as a first-class
reactivity primitive, which means a plain @Input() property is just that — a
plain property, with no signal wrapping it, no way to derive a computed() value
directly from it, nothing connecting it to the rest of Angular’s newer reactivity
model without extra plumbing. input(), model(), and output() exist to close
that gap: the same two jobs from the previous lesson, expressed as functions that
return signals instead of decorators that mark plain properties.
input(): the same job, returned as a signal
@Component({ selector: 'app-user-card', standalone: true, /* ... */ })
export class UserCardComponent {
user = input.required<User>();
// or, with a default: role = input<string>('member');
}
<app-user-card [user]="selectedUser"></app-user-card>
The parent-side binding syntax is identical to @Input() — [user]="selectedUser",
no change at all. What changes is how the component reads its own input: user
is now a signal, so you call it — this.user() — rather than reading it as a
plain property. input.required<User>() marks it mandatory (the compiler flags a
missing binding at build time, something @Input() alone never guaranteed as
strictly); plain input() takes an optional default value.
Because it’s a real signal, you can derive from it directly with computed(),
something a plain @Input() property never let you do without first copying it
into a signal yourself.
model(): when the child needs to write back
A plain input is one-directional — the parent sets it, the child reads it, done.
Sometimes a child genuinely needs to write a new value back to the parent, the
same relationship [(ngModel)] has with whatever it’s bound to. That’s what
model() is for:
@Component({ selector: 'app-counter', standalone: true, /* ... */ })
export class CounterComponent {
count = model(0);
increment() {
this.count.update((n) => n + 1);
}
}
<app-counter [(count)]="currentCount"></app-counter>
The parent uses two-way binding syntax — [(count)] — the same banana-in-a-box
pattern from the [(ngModel)] lesson. Inside the component, calling
this.count.update(...) (or .set(...)) doesn’t just change the local signal; it
propagates back up and updates currentCount on the parent, because model()
wires up both the read and the write side of that binding for you. This is the
building block custom form-like components are made from — a star-rating widget,
a custom toggle, anything where the component both displays a value and lets the
user change it.
output(): the same emit, without constructing an EventEmitter
@Component({ selector: 'app-delete-button', standalone: true, /* ... */ })
export class DeleteButtonComponent {
deleteRequested = output<void>();
onClick() {
this.deleteRequested.emit();
}
}
<app-delete-button (deleteRequested)="onDelete()"></app-delete-button>
Functionally this is the same mechanism as @Output() x = new EventEmitter() —
the parent listens with the identical (deleteRequested)="..." syntax, and
.emit() fires it the same way. The difference is entirely in how the child
declares it: output() is a plain function call, not a decorator plus a manual
new EventEmitter() construction.
Migrating is mechanical, but not required all at once
Both styles can coexist in the same codebase — a component using @Input() and
a component using input() interoperate fine from a consuming template’s
perspective, since the parent-side binding syntax never changes either way. This
lesson’s video walks through input() specifically; the two linked videos go
deeper on model() as the direct @Input()/@Output() replacement for
two-way-bound components.
Check yourself
You migrate `@Input() userId!: string;` to `userId = input<string>();`. What has to change everywhere you read `this.userId` inside that component?
Every read becomes `this.userId()` — a function call, since `input()` returns a signal, not a plain value. The binding syntax a parent uses to set it, `[userId]="..."`, stays exactly the same; only how the component itself reads the value changes.
What can a parent do with a component's `model()`-based property that it can't do with a plain `input()`-based one?
Bind to it two-way, with `[(value)]="someProperty"` — a `model()` lets the child write back to update the parent's bound value, the same relationship `[(ngModel)]` has with a form control. A plain `input()` is read-only from the child's side; it has no mechanism to push a value back up.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.