Thuta Learning
Angular
IntermediateWeb DevelopmentIntermediate

@Output() - Child to Parent

AngularLesson 1920 min

What you'll walk away with

  • Explain the core concept and Angular data flow of @Output() - Child to Parent
  • Run the example, predict its state and UI, and test edge and error cases
  • Apply a typed safe pattern in a real project and recognize common pitfalls

Explain it simply

@Output() - Child to Parent, in plain language

@Output() and EventEmitter are used to pass events/data from a child component up to a parent component.

Problem → Why → Solution

The problem — why this concept matters

Emitting an entire state object as every output payload tightly couples components.

A common mistake

One happy-path result does not prove the feature works; empty, loading, error, and cleanup behavior need explicit tests.

Core concept — understand how it works

An output is a typed event contract that sends child intent or results to a parent without directly modifying parent data. Keep payloads minimal and domain-specific, and avoid names that collide with native DOM events. Broader sibling or application coordination usually belongs in a service or state layer rather than an output-based command bus.

Mental model
  1. user input
  2. binding and validation
  3. valid state or feedback

Explain the core concept and Angular data flow of @Output() - Child to Parent

Core syntax or pattern

typescript
// child.component.ts
import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <button (click)="sendData()">Send to Parent</button>
  `
})
export class ChildComponent {
  @Output() dataEvent = new EventEmitter<string>();
  
  sendData() {
    this.dataEvent.emit('Hello from Child!');
  }
}

// parent.component.ts
@Component({
  selector: 'app-parent',
  template: `
    <app-child (dataEvent)="receiveData($event)"></app-child>
    <p>{{ message }}</p>
  `
})
export class ParentComponent {
  message = '';
  
  receiveData(data: string) {
    this.message = data;
  }
}

An output is a typed event contract that sends child intent or results to a parent without directly modifying parent data. Keep payloads minimal and domain-specific, and avoid names that collide with native DOM events. Broader sibling or application coordination usually belongs in a service or state layer rather than an output-based command bus.

Read the code step by step

  1. user input// child.component.ts

    @Output() and EventEmitter are used to pass events/data from a child component up to a parent component.

  2. binding and validation// parent.component.ts

    An output is a typed event contract that sends child intent or results to a parent without directly modifying parent data. Keep payloads minimal and domain-specific, and avoid names that collide with native DOM events. Broader sibling or application coordination usually belongs in a service or state layer rather than an output-based command bus.

  3. valid state or feedback}

    Have a task row emit toggle and delete intent while its parent performs immutable list updates, sending only the required ID.

Execution flow
  1. user input
  2. binding and validation
  3. valid state or feedback

Success

Explain the core concept and Angular data flow of @Output() - Child to Parent

Failure

Emitting an entire state object as every output payload tightly couples components.

@Output() and EventEmitter are used to pass events/data from a child component up to a parent component.

typescript
// child.component.ts
import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <button (click)="sendData()">Send to Parent</button>
  `
})
export class ChildComponent {
  @Output() dataEvent = new EventEmitter<string>();
  
  sendData() {
    this.dataEvent.emit('Hello from Child!');
  }
}

// parent.component.ts
@Component({
  selector: 'app-parent',
  template: `
    <app-child (dataEvent)="receiveData($event)"></app-child>
    <p>{{ message }}</p>
  `
})
export class ParentComponent {
  message = '';
  
  receiveData(data: string) {
    this.message = data;
  }
}
You should see
(Clicking the button in the child component makes 'Hello from Child!' appear in the parent component)

Real-world usage

How to apply it in a real project

Have a task row emit toggle and delete intent while its parent performs immutable list updates, sending only the required ID.

Mini challenge

Build it yourself

Rebuild the @Output() - Child to Parent example without copying it. Add two normal states, one edge case, and one failure state, and write the expected UI and state transition before running it.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
typescript
// child.component.ts
import { Component, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <button (click)="sendData()">Send to Parent</button>
  `
})
export class ChildComponent {
  @Output() dataEvent = new EventEmitter<string>();
  
  sendData() {
    this.dataEvent.emit('Hello from Child!');
  }
}

// parent.component.ts
@Component({
  selector: 'app-parent',
  template: `
    <app-child (dataEvent)="receiveData($event)"></app-child>
    <p>{{ message }}</p>
  `
})
export class ParentComponent {
  message = '';
  
  receiveData(data: string) {
    this.message = data;
  }
}

Expected: Explain the core concept and Angular data flow of @Output() - Child to Parent

Show hint

Have a task row emit toggle and delete intent while its parent performs immutable list updates, sending only the required ID.

Quick quiz 1 / 3

What best describes the core idea of @Output() - Child to Parent?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • user input → binding and validation → valid state or feedback
  • An output is a typed event contract that sends child intent or results to a parent without directly modifying parent data. Keep payloads minimal and domain-specific, and avoid names that collide with native DOM events. Broader sibling or application coordination usually belongs in a service or state layer rather than an output-based command bus.
  • Emitting an entire state object as every output payload tightly couples components.
  • Have a task row emit toggle and delete intent while its parent performs immutable list updates, sending only the required ID.

Angular — Components — Angular

Easy traps

  • Emitting an entire state object as every output payload tightly couples components.
  • One happy-path result does not prove the feature works; empty, loading, error, and cleanup behavior need explicit tests.

Hands-on Exercise

Rebuild the @Output() - Child to Parent example without copying it. Add two normal states, one edge case, and one failure state, and write the expected UI and state transition before running it.

You'll know it worked when: (Clicking the button in the child component makes 'Hello from Child!' appear in the parent component)

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

@Output() - Child to Parent | Thuta Learning