Inputs and outputs: @Input, @Output, and EventEmitter

Intermediate · 16 min

How a parent passes data down to a child component, and how a child reports back up.

Before thisComponent basics and the @Component decorator

codewithjana · 16 min

Inputs and outputs: @Input, @Output, and EventEmitter

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by codewithjanaReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • @Input() exposes a component property as something a parent template can bind to with `[property]="..."`, the same property-binding syntax you already know.
  • @Output() combined with EventEmitter lets a child notify its parent — the parent listens with ordinary `(event)="..."` syntax, same as any native DOM event.
  • Data only flows one direction on each channel: inputs flow down, outputs flow up. There's no built-in way for a child to directly reach up and set a value on its parent.

A component tree needs two directions of communication

Break an app into nested components and you immediately need two things: a way for a parent to hand data down to a child (so a UserCard can be told which user to render), and a way for a child to report something back up to its parent (so a DeleteButton inside that card can tell the parent “the user clicked delete, you decide what happens”). Those are genuinely different problems — one is “configure this child,” the other is “this child wants to tell you something happened” — and Angular gives each one its own dedicated mechanism rather than one general-purpose channel for both.

@Input(): data flowing down

@Component({ selector: 'app-user-card', standalone: true, /* ... */ })
export class UserCardComponent {
  @Input() user!: User;
}
<app-user-card [user]="selectedUser"></app-user-card>

@Input() marks a property as something a parent is allowed to bind into from the outside. Notice the binding syntax: [user]="selectedUser" is exactly the property-binding syntax from several lessons ago — Angular doesn’t invent a separate syntax for “pass data to a custom component” versus “set a DOM element’s property.” A component input is, from the template’s point of view, just another property to bind.

@Output() and EventEmitter: data flowing up

@Component({ selector: 'app-delete-button', standalone: true, /* ... */ })
export class DeleteButtonComponent {
  @Output() deleteRequested = new EventEmitter<void>();

  onClick() {
    this.deleteRequested.emit();
  }
}
<app-delete-button (deleteRequested)="onDelete()"></app-delete-button>

@Output() exposes an EventEmitter as something a parent can listen to, and .emit() fires it. The parent’s syntax — (deleteRequested)="onDelete()" — is, again, the exact same event-binding syntax you already use for (click) on a native button. Angular deliberately keeps custom-component events indistinguishable, syntactically, from native DOM events: from the template’s perspective, listening to a child component’s output and listening to a button’s click are the same kind of thing.

If the output carries data, .emit() takes a payload and the parent receives it as $event, same as any native event:

@Output() rated = new EventEmitter<number>();
// this.rated.emit(5);
<app-star-rating (rated)="onRated($event)"></app-star-rating>

One direction per channel, on purpose

A child cannot reach up and directly set a property on its parent — there’s no @Input()-but-backwards. That’s a deliberate constraint, not a missing feature. If a child could silently reach up and mutate its parent’s state, you’d lose the ability to look at a parent component and know, just from its own template, every place its own state can change — any child, anywhere in the tree, could be doing it invisibly. Keeping the flow strictly one-directional on each channel — inputs down, outputs up — means the parent’s template is the only place that decides what happens in response to a child’s output, which keeps that decision visible and in one place instead of scattered across however many components happen to be nested inside it.

This lesson’s video builds a working parent-child pair using both decorators together — the linked “deeper” video focuses specifically on the output side, useful if you want a second pass once the basic mechanism here is settled.

What’s next

The next lesson covers input(), model(), and output() — the newer, signal-based functions that do largely the same two jobs as @Input()/@Output(), with a different API shape worth understanding on its own terms rather than as a literal replacement.

Check yourself

  1. 01A parent template has `<app-rating [score]="currentScore"></app-rating>`. What does the `RatingComponent` need, at minimum, for that binding to work?

    A property named `score`, decorated with `@Input()` — `@Input() score!: number;` (or the signal-based `score = input<number>()` covered in the next lesson). Without the decorator, `[score]` would just be an unbound, meaningless attribute as far as Angular's compiler is concerned.

  2. 02Inside a child component, you have `@Output() rated = new EventEmitter<number>();`. What does calling `this.rated.emit(5)` actually do?

    It fires the `rated` event with the payload `5`, which any parent listening via `(rated)="onRated($event)"` receives as `$event` — exactly the same event-binding mechanism you already use for native DOM events, just backed by a custom `EventEmitter` instead of the browser's own event system.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark