Component Communication: @Input & @Output

Master the bidirectional flow of data in Angular. Connect your components using Inputs to pass data down and Outputs to emit events up.

Simulation ProgressStep 1 of 8
Parent Component
⬇️ [Data]
Child Component
0 EXP

Welcome! Let's visualize how Angular components communicate. We'll start with a parent passing data to a child.

// app.component.ts (Parent)

The Concept of Data Flow

Angular applications are trees of components. The most fundamental rule is that data flows down (from parent to child) and events flowup (from child to parent). This is known as Unidirectional Data Flow.

👨‍👦

Components should not mutate each other's state directly. Instead, they should communicate via well-defined APIs: Inputs and Outputs.

Compiler Check

In Angular, which direction does data typically flow?

Advanced Holo-Simulations

0 EXP

Aplica tus conocimientos en estas simulaciones avanzadas. ¡Todo nuestro contenido es gratuito!


Achievements

📦
Data Courier

Successfully configure an @Input() to receive data.

📡
Broadcaster

Wire up an @Output() and EventEmitter correctly.

🔄
Full Duplex

Master the bidirectional flow: Input down, Output up.

Mission: Construct a Two-Way Component

Write a component class that accepts an input and has an output emitter. The AI will analyze your syntax.

A.D.A. Analysis:

> Component structure verified. Communication lines active.

Challenge: The Communication Lifecycle

Drag the steps into the logical order of a full communication cycle (Parent sends data -> Child replies).

1. Parent: [item]="data"
3. Child: emit(event)
2. Child: @Input() item
4. Parent: (event)="handle()"

Challenge: Syntax Completion

Fill in the missing Angular keywords (without the @ symbol).

@() user: User;
@() onSave = new EventEmitter();
save() { this.onSave.(); }

Consult A.D.A. (Angular Dev Assistant)

Community Holo-Net

Peer Project Review

Submit your "Component Communication" patterns for feedback.

Mastering Data Flow: Beyond the Basics

Angular's architecture relies heavily on a strict hierarchy of components. Understanding how to move data efficiently between these components is the difference between a spaghetti-code application and a scalable enterprise solution. While @Input and @Output are the bread and butter, nuances exist that every developer must master.

Unidirectional Data Flow

Angular enforces unidirectional data flow. Data flowsdown from parent to child via property bindings, and events flowup from child to parent via event bindings. This predictability makes debugging significantly easier because you always know where data is coming from.

Intercepting Inputs: ngOnChanges vs. Setters

Often, you need to react when an input value changes. You have two main options:

  • ngOnChanges() lifecycle hook: Best when you need to watch multiple inputs simultaneously or need the previous value of the input.
  • TypeScript Setters: Best for reacting to a specific input change in isolation.
// Using a Setter for interception
private _amount: number;

@Input()
set amount(value: number) {
  this._amount = value < 0 ? 0 : value; // Validation logic
}
get amount(): number { return this._amount; }

Alternative Patterns: ViewChild & Services

@ViewChild()

Allows a parent to access public methods and properties of a child directly. Useful for controlling child logic (e.g., `child.resetForm()`), but tightly couples components.

Shared Services

For components that are siblings or far apart in the tree. Uses RxJS `BehaviorSubject` to hold state. The "Angular Way" for global state.

Pro Tip: Avoid "Input Drilling" (passing data through 5 layers of components just to reach the bottom). If you pass data down more than 2-3 layers, consider using a Shared Service or a state management library like NgRx or Signals.

Component Communication Glossary

@Input()
A decorator that marks a class field as an input property and supplies configuration metadata. The input property is bound to a DOM property in the template.
@Output()
A decorator that marks a property in a child component as a doorway through which data can travel from the child to the parent. Usually initialized with `new EventEmitter()`.
EventEmitter
Use in components with the `@Output` directive to emit custom events synchronously or asynchronously, and register handlers for those events by subscribing to an instance.
Property Binding [ ]
One-way data binding from the component's class to an element property. Syntax: `[property]="expression"`.
Event Binding ( )
Allows you to listen for and respond to user actions such as keystrokes, mouse movements, clicks, and touches. Syntax: `(event)="handler()"`.
Aliasing
Renaming the input/output for the external template while keeping a different variable name internally. E.g., `@Input('account-id') id: string;`.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This tutorial was crafted by our frontend architecture team, verified against Angular v17+ standards.

Verification and Updates

Last reviewed: October 2025.

We ensure all code snippets are compliant with strict TypeScript configuration and modern Angular best practices.

External Resources

Found an error or have a suggestion? Contact us!