Component Communication: input, output and model
Data Down, Events Up
text
Parent --- input() ---> Child (data goes down)
Parent <-- output() --- Child (events go up)
input(): Receive Data
typescript
import { Component, input } from '@angular/core';
export interface Product { id: number; name: string; price: number; }
@Component({
selector: 'app-product-card',
template: `
<div class="card">
<h3>{{ product().name }}</h3>
<p>{{ product().price | currency }}</p>
<small>{{ label() }}</small>
</div>
`,
})
export class ProductCard {
product = input.required<Product>(); // must be provided
label = input('In stock'); // optional with default
}
html
<app-product-card [product]="item" label="Limited" />
<app-product-card [product]="other" />
Reading inputs: An
input() is a signal. Read it with product(). It works with computed() and effect() out of the box.
Input Options
typescript
import { booleanAttribute, numberAttribute } from '@angular/core';
size = input(10, { transform: numberAttribute }); // "20" becomes 20
active = input(false, { transform: booleanAttribute }); // <app-x active> becomes true
title = input('', { alias: 'cardTitle' }); // <app-x cardTitle="Hi">
doubled = computed(() => this.size() * 2);
output(): Send Events
typescript
import { Component, input, output } from '@angular/core';
@Component({
selector: 'app-product-card',
template: `
<h3>{{ product().name }}</h3>
<button (click)="addToCart.emit(product())">Add to cart</button>
<button (click)="removed.emit()">Remove</button>
`,
})
export class ProductCard {
product = input.required<Product>();
addToCart = output<Product>();
removed = output<void>();
}
html
<app-product-card
[product]="item"
(addToCart)="cart.add($event)"
(removed)="removeItem(item.id)" />
$event holds the value passed to emit().
model(): Two-Way Binding for Your Own Components
typescript
@Component({
selector: 'app-rating',
template: `
@for (star of [1,2,3,4,5]; track star) {
<button (click)="value.set(star)" [class.on]="star <= value()">★</button>
}
`,
})
export class Rating {
value = model(0);
}
html
<app-rating [(value)]="myRating" />
<p>You rated {{ myRating() }} stars</p>
Complete Example: Parent
typescript
@Component({
selector: 'app-shop',
imports: [ProductCard],
template: `
<h2>Shop ({{ cart().length }} in cart)</h2>
@for (p of products; track p.id) {
<app-product-card [product]="p" (addToCart)="add($event)" />
}
`,
})
export class Shop {
products: Product[] = [
{ id: 1, name: 'Keyboard', price: 49 },
{ id: 2, name: 'Mouse', price: 19 },
];
cart = signal<Product[]>([]);
add(p: Product) { this.cart.update(c => [...c, p]); }
}
Older Decorator Style
typescript
@Input() product!: Product;
@Output() addToCart = new EventEmitter<Product>();
You will see @Input() and @Output() in many existing projects. They still work, but new code should use input(), output() and model().
Keep children simple: A child should receive data and emit events. It should not know about services of the parent or change the parent's data directly.
Conclusion
input() brings data into a component, output() sends events out and model() gives two-way binding. All are signal friendly and type safe.
Quick Summary: input() down, output() up, model() both ways.

