@Input and @Output are the standard way a parent and child component communicate: @Input passes data (parent → child), and sends events (child → parent). This mirrors the universal "props down, events up" pattern.
@Input and @Output are the standard way a parent and child component communicate: @Input passes data (parent → child), and sends events (child → parent). This mirrors the universal "props down, events up" pattern.
@Output// child: UserCardComponent
import { Component, Input } from "@angular/core";
@Component({ selector: "app-user-card", template: `<h2>{{ user.name }}</h2>` })
export class UserCardComponent {
@Input() user!: User; // receives data from the parent
@Input() showEmail = false; // with a default
}
<!-- parent passes data via property binding -->
<app-user-card [user]="currentUser" [showEmail]="true"></app-user-card>
// child emits an event the parent can listen to
import { Component, Output, EventEmitter } from "@angular/core";
@Component({
selector: "app-user-card",
template: `<button (click)="onDelete()">Delete</button>`,
})
export class UserCardComponent {
@Output() deleted = new EventEmitter<number>(); // declares an output event
onDelete() {
this.deleted.emit(this.user.id); // emit with a payload
}
}
<!-- parent listens via event binding -->
<app-user-card [user]="u" (deleted)="removeUser($event)"></app-user-card>
The child emits through an EventEmitter; the parent binds to it with (eventName) and receives the payload as $event. The child never modifies the parent's data directly — it requests action by emitting.
Parent ──[user]──────────────→ Child (@Input: data down)
Parent ←──(deleted)=removeUser─ Child (@Output: events up)
name = input<string>(); // signal-based @Input (newer Angular)
deleted = output<number>(); // signal-based @Output
Recent Angular adds signal-based input()/output() functions as an alternative.
@Input/@Output are the core of parent-child communication and reusable components in Angular — they enforce one-way data flow (down via inputs, up via events) that keeps data predictable and components decoupled.
Understanding this pair is essential for composing any non-trivial Angular UI; for communication between unrelated components, you'd instead use a shared service or state library.