Working with @Output and EventEmitter

In Angular, we can handle user events using a property whose value is an event emitter. The property must be decorated with the @Output decorator as demonstrated by the following code snippet:

import { Component, EventEmitter, Input, Output } from "@angular/core"; @Component({ selector: "app-text-field", template: ` <input type="text" className="form-control" [id]="id" [placeholder]="placeholder" (input)="onEdit($event)" /> ` }) export class TextFieldComponent { @Input() public id!: string; @Input() public placeholder!: string; @Output() public onChange = new EventEmitter<{k: string; v: string}>(); public onEdit(event: any) { const value = (event.target as any).value; const key = (event.target as any).id; ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.