The Modern Angular Communication Guide: Signals, Inputs, Outputs & Models
Signal-Based Inputs & Outputs: Say goodbye to @Input() decorators; manage two-way bindings effortlessly using input(), output(), and model().
For years, Angular components communicated across boundaries using decorators: @Input(), @Output(), and EventEmitter. While familiar, these decorators came with chronic design flaws:
- **Fake compile-time safety:** Declaring @Input() id!: string bypassed TypeScript's strict null checks with a non-null assertion (!). If a parent omitted the property, it was quietly undefined at runtime.
- **Messy change listeners:** Reacting to input updates meant wrestling with ngOnChanges (and its string-keyed SimpleChanges map) or maintaining paired private fields with getters and setters.
- **Event emitter overhead:** Every @Output() instantiated an RxJS Subject behind the scenes, creating unnecessary runtime overhead for straightforward DOM-style custom events.
- **Tedious two-way binding:** Creating a two-way [(value)] binding required hand-authoring an input/output naming pair (@Input() value + @Output() valueChange).
- Modern Angular replaces this decorator-heavy model with a unified, Signal-based communication API: input(), output(), and model().
## 1. Quick Reference: The Evolution
| Capability | Legacy Decorator API | Modern Signal-Based API | Optional Input |
| --- | --- | --- | --- |
| @Input() count = 0; | count = input(0); (InputSignal<number>) | Required Input | @Input() id!: string; (risky assertion) |
| id = input.required<string>(); (enforced at compile time) | Input Transformation | Verbose getter/setter or ngOnChanges | disabled = input(false, \{ transform: booleanAttribute \}); |
| Reacting to Changes | ngOnChanges(changes: SimpleChanges) | computed(() => ...) or effect(() => ...) | Component Output |
| @Output() saved = new EventEmitter<User>(); | saved = output<User>(); (OutputEmitterRef<User>) | Two-Way Binding | @Input() val; @Output() valChange; |
| val = model(0); (ModelSignal<number>) | Template Read Syntax | \{\{ count \}\} (plain property) | \{\{ count() \}\} (invoked signal) |
## 2. Signal Inputs: input() and input.required()
Signal inputs are read-only reactive getters. When a parent passes a new value, the input signal updates instantly, notifying any dependent computed() values or template bindings.
### 2.1 Basic Usage & Compile-Time Guarantees
```ts
import { Component, input, computed } from '@angular/core';
@Component({
selector: 'app-user-badge',
standalone: true,
template: `
role = input('Member');
// 2. Optional input without a fallback -> InputSignal
nickname = input();
// 3. Required input -> InputSignal (guaranteed never undefined)
username = input.required();
// Inputs compose naturally with computed signals:
initials = computed(() => this.username().slice(0, 2).toUpperCase());
}
```
```html
```
### 2.2 Built-in and Custom Transforms
HTML attributes often arrive as plain strings—such as <my-widget disabled />, which passes an empty string "" or "true". Previously, casting these required backing fields and manual setter functions.
Signal inputs handle coercion declaratively:
```ts
import { Component, input, booleanAttribute, numberAttribute } from '@angular/core';
@Component({
selector: 'app-numeric-slider',
standalone: true,
template: `...`
})
export class NumericSliderComponent {
// Converts "" or "true" -> true; null/undefined -> false
disabled = input(false, { transform: booleanAttribute });
// Coerces string-based numbers ("10") into real JavaScript numbers (10)
min = input(0, { transform: numberAttribute });
max = input(100, { transform: numberAttribute });
// Custom Transform: normalize or sanitize inputs on arrival
slug = input('', {
transform: (value: string) => value.trim().toLowerCase().replace(/\s+/g, '-')
});
}
```
### 2.3 Aliasing Inputs
If the public HTML binding name needs to differ from the internal TypeScript property name, pass the alias option:
```ts
export class UserProfileComponent {
// Public HTML binding is [user-id], internal signal is userId()
userId = input.required({ alias: 'user-id' });
}
```
## 3. Lightweight Event Communication: output()
The modern output() function dispatches custom component events without dragging in RxJS Subject or EventEmitter.
### 3.1 Emitting Events
```ts
import { Component, output } from '@angular/core';
export interface DeleteEvent {
id: number;
reason: string;
}
@Component({
selector: 'app-record-row',
standalone: true,
template: `
`
})
export class RecordRowComponent {
// Produces an OutputEmitterRef
recordDeleted = output();
// Aliased output
cancelled = output({ alias: 'onCancel' });
confirmDelete(): void {
this.recordDeleted.emit({ id: 101, reason: 'User requested removal' });
}
}
```
Parents listen to output() identical to legacy outputs:
```html
```
### 3.2 RxJS Interop with outputFromObservable
If your component's internal logic is already powered by an RxJS stream (like a debounced search input), bridge it directly to an output without manual subscriptions:
```ts
import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { outputFromObservable } from '@angular/core/rxjs-interop';
import { debounceTime, distinctUntilChanged } from 'rxjs';
@Component({
selector: 'app-search-box',
standalone: true,
imports: [ReactiveFormsModule],
template: ``
})
export class SearchBoxComponent {
searchControl = new FormControl('', { nonNullable: true });
// Automatically subscribes and emits changes out through the component interface
searchDebounced = outputFromObservable(
this.searchControl.valueChanges.pipe(
debounceTime(300),
distinctUntilChanged()
)
);
}
```
## 4. Seamless Two-Way Binding: model()
Historically, two-way binding required memorizing the matching Change naming convention:
- @Input() open: boolean;
- @Output() openChange = new EventEmitter<boolean>();
- One minor spelling error (like openedChange) silently severed the link.
The model() primitive defines a writable signal that acts as an input, an output, and internal state simultaneously:
```ts
import { Component, model } from '@angular/core';
@Component({
selector: 'app-toggle-switch',
standalone: true,
template: `
`
})
export class ToggleSwitchComponent {
// Creates [checked], (checkedChange), and [(checked)] all in one line
checked = model(false);
toggle(): void {
// Model signals are WRITABLE inside the child component:
this.checked.update(prev => !prev);
}
}
```
### 4.1 Consuming model() in Templates
A parent component can consume a model() in three different ways:
```html
To enforce that a parent must wire up the model, use model.required():
```
```ts
export class PaginationComponent {
page = model.required();
}
```
## 5. Architectural Breakdown: signal() vs. input() vs. model()
signal()
```text
(Local writable state inside a single component)
│
┌──────────────┴──────────────┐
▼ ▼
input() model()
• Read-only in the child • Writable in the child
• Values flow downward • Values sync both directions
• 90% of presentation data • Form inputs, modals, tabs, toggles
```
## 6. End-to-End Walkthrough: Interactive Modal Dialog
Here is how input(), output(), and model() combine to create a clean confirmation modal:
### The Modal Component
```ts
// src/app/ui/confirm-modal.component.ts
import { Component, input, output, model } from '@angular/core';
@Component({
selector: 'app-confirm-modal',
standalone: true,
template: `
@if (isOpen()) {
}
`
})
export class ConfirmModalComponent {
// Two-way bound visibility
isOpen = model.required();
// Read-only configuration inputs
title = input('Confirmation');
message = input.required();
// Event notifications
confirmed = output();
cancelled = output();
close(): void {
this.isOpen.set(false); // Synchronizes immediately with the parent!
this.cancelled.emit();
}
confirm(): void {
this.confirmed.emit();
this.isOpen.set(false);
}
}
```
### The Parent Host
```ts
// src/app/pages/dashboard.component.ts
import { Component, signal } from '@angular/core';
import { ConfirmModalComponent } from '../ui/confirm-modal.component';
@Component({
selector: 'app-dashboard',
standalone: true,
imports: [ConfirmModalComponent],
template: `
`
})
export class DashboardComponent {
isModalOpen = signal(false);
onDeleteAccount(): void {
console.log('Account deleted.');
}
}
```
## 7. Automated Migration
To convert existing components across an entire project, run Angular's automated migration tool:
```bash
ng generate @angular/core:signal-input-migration
```
What it updates:
- Converts @Input() declarations to input() and input.required().
- Updates child template usages from value to value().
- Auto-configures standard coercions with booleanAttribute or numberAttribute.
- Detects matching @Input() and @Output() pairs and converts them into model().
- Core Takeaways
- **Read with parentheses:** Read signal inputs just like standard signals: myInput().
- **Lock in required props:** Use input.required() to eliminate non-null assertions and catch missing bindings during compilation.
- **Keep events lean:** Use output() instead of EventEmitter to dispatch events without RxJS overhead.
- **Simplify two-way syncing:** Reach for model() whenever a child component needs to update a property received from its parent.
{{ initials() }}
`
})
export class UserBadgeComponent {
// 1. Optional input with a fallback value -> InputSignal