NG.I · Angular 22 practice question

A developer is creating a reusable UI widget and needs to notify its parent component when a specific internal action occurs, such as a 'dataSaved' event. Which mechanism should they use to expose this event to the parent component?

export class DataWidgetComponent {
  dataSaved = output<void>();
  saveData() {
    // ... logic to save data
    this.dataSaved.emit();
  }
}
Choose one answer
Check answer and explanation

Correct answer: Define a property using the `output` function and call `.emit()` on it when the event fires.

Explanation

Defining a property using the `output` function and call `.emit()` on it when the event fires is the prescribed way to raise custom events in Angular components.

Common trap

Declaring a public method is not how Angular components expose custom events, and using `@Input()` is for receiving data, not emitting events.

Source: Angular docs: Custom events with outputs — Custom events with outputs
Checked against the cited text on 2026-11-25.

Report an error in this question