Menu
CoddyTech

Component Outputs

Part of the Fundamentals section of Coddy's Angular journey. Lesson 28 of 55.

A child reports an action with an output event. Create an EventEmitter field marked with Output, then emit a payload when the action occurs. The parent handles that event using its own binding.

// Child field: @Output() picked=new EventEmitter<string>();
// Child button: <button (click)="picked.emit('Blue')">Pick</button>
// Parent: <color-card (picked)="selected.set($event)"></color-card>

The parent receives the emitted payload as $event. It can update its own state without the child reaching into parent fields. Use Output to declare the event and EventEmitter to send its payload.

challenge icon

Challenge

Medium

Have ChoiceCard emit its drink choice through picked. The parent must display the latest payload in selected, initially None. Clicking Tea displays Tea.

Edit the supplied files. Press Run preview to refresh the preview after edits, then use Check or Run code to grade your work. Keep the requested element IDs.

Try it yourself

<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="styles.css"></head><body><app-root></app-root><script type="module" src="main.ts"></script></body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals