Skip to main content

Overview

Angular provides two primary mechanisms for component communication: inputs for passing data from parent to child, and outputs for emitting events from child to parent.

@Input Decorator

Signature

Parameters

string | Input
Either an alias string or a configuration object.

Input Options

string
Alternative name for the input in templates.
boolean
Whether the input must be provided. Causes compile error if missing.
(value: any) => any
Function to transform the input value before assignment.

Basic Input Example

user-card.component.ts
Usage:

Input with Alias

product.component.ts
Usage:

Required Inputs

profile.component.ts

Input Transforms

toggle.component.ts
Usage:

input() Function (Signal-Based)

Signature

Signal Input Example

counter.component.ts
Usage:

Required Signal Input

item-detail.component.ts

Signal Input with Transform

date-display.component.ts

@Output Decorator

Signature

Parameters

string
Alternative name for the output in templates.

Basic Output Example

button.component.ts
Usage:

Output with Data

search.component.ts
Usage:

Output with Alias

dropdown.component.ts
Usage:

output() Function (Signal-Based)

Signature

Signal Output Example

modern-button.component.ts

Output with Custom Event Type

item-list.component.ts

Two-Way Binding

NgModel Pattern

custom-input.component.ts
Usage:

Signal-Based Two-Way Binding

signal-input.component.ts
Usage:

Parent-Child Communication Example

parent.component.ts
child.component.ts

Best Practices

  • Use signal inputs (input()) for new code - they’re more performant
  • Mark inputs as required when they’re essential for component function
  • Use input transforms for common conversions (boolean, number)
  • Prefer descriptive event names for outputs (e.g., userSelected over select)
  • Use TypeScript types for output events to ensure type safety
  • Don’t mutate input objects - create new objects instead
  • Always complete EventEmitters in ngOnDestroy if they’re long-lived
  • Avoid complex logic in input setters
  • Don’t emit outputs in ngOnInit or constructor

Comparison: Decorator vs Function

See Also

Component Inputs

Learn about input properties

Component Outputs

Master output events

Signals

Understand signal reactivity

Two-Way Binding

Implement two-way binding